home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Storage / LinkDlgs.cpp < prev    next >
Encoding:
Text File  |  1996-04-22  |  72.2 KB  |  2,356 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        LinkDlgs.cpp
  3.  
  4.     Contains:    implementation of the Paste As and Link Info dialogs
  5.  
  6.     Owned by:    Craig Carper
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     1/12/96    CC        1301094: Hide static text obscuring Editor
  13.                                     popup.
  14.                                     1298118: Disable manual/automatic buttons
  15.                                     if Paste with Link unchecked.
  16.         <58>    10/16/95    CC        GM 1292157: Moved TranslateValueTypes,
  17.                                     AddTranslationKindToMenu,
  18.                                     GetMenuStringForKind,
  19.                                     DefaultMenuStringForKind,
  20.                                     StringPtrFromStrHandle to InfoUtil.cpp.
  21.         <57>    10/10/95    DM        1285040: GM: PasteAs into part viewed in
  22.                                     window hangs (dont assume persistent frame
  23.                                     in ShowPasteAsDialog())
  24.         <56>     10/3/95    eeh        1284995: new default param to
  25.                                     SetDialogTextStyle
  26.         <55>     10/3/95    TJ        Changes done by RefBall Team
  27.         <54>     9/12/95    DM        1280020 FB1 part trans dlg mem leaks
  28.         <53>      9/8/95    TÇ        1281096 FB2:Many constants in ODTypesB
  29.                                     without kOD prefix!
  30.         <52>      9/1/95    CC        1279449: Initialize dlg to null & use
  31.                                     ODVolatile.
  32.                                     ShowLinkSourceInfo,
  33.                                     ShowLinkDestinationInfo: Use ODVolatile.
  34.         <51>     8/29/95    DM        1221778, 1276165: [ShowLinkUpdateAlert]
  35.                                     drop count arg in ShowLinkUpdateAlert
  36.         <50>     8/26/95    TÇ        1274606 FB2: Patching Remarks
  37.         <49>     8/25/95    eeh        1230007: new param to DrawITextInDlogBox
  38.         <48>     8/23/95    CC        1278378: ShowPasteAsDialog behaves
  39.                                     incorrectly on switch from Embed to Merge.
  40.                                     1242581: ShowPasteAsDialog should respect
  41.                                     preferred editor.
  42.                                     1278840: ShowPasteAsDialog should respect
  43.                                     preferred kind.
  44.         <47>     8/15/95    CC        1276520: Adapted to changes to
  45.                                     ShowTranslateDialog.
  46.         <46>     8/12/95    TÇ        1276812 Need to use TempObjs and TempRefs
  47.                                     for exception safety and to avoid TRY
  48.                                     blocks, 1276807 Opt./Bug: use StdTypIO
  49.                                     routines for portable streaming & smaller
  50.                                     footprint
  51.         <45>     7/28/95    CC        1242576: Removed obsolete Others dialog
  52.                                     code.
  53.         <44>     7/24/95    CC        1236616: Use CreateTypeList factory method.
  54.         <43>     7/18/95    eeh        1222282: move constants to DlogUtil.h
  55.         <42>     6/21/95    CC        1260937: BB: ODTypeListIterator must return
  56.                                     copies of ODType values.
  57.         <41>     6/16/95    CC        1258538: ShowPasteAsDialog: Release kind
  58.                                     and editor menu resources and delete the
  59.                                     menu; also check GetMenu result.
  60.                                     1257141: TranslateValueTypes: Changed
  61.                                     translateFromList parameter to
  62.                                     OrderedCollection. Added
  63.                                     GetIndexedElement() function.
  64.                                     SetDateTimeStrings: Added
  65.                                     CUsingLibraryResources.
  66.                                     DefaultMenuStringForKind: Added
  67.                                     CUsingLibraryResources.
  68.         <40>      6/7/95    jpa        Fixed EndUsingLibRsrcs calls. [1255369]
  69.         <39>      6/7/95    CC        1236299:  Wrap individual calls with using
  70.                                     library resources calls.
  71.         <38>      6/2/95    CC        1255476: ShowPasteAsDialog: Release object
  72.                                     returned by ODFrame::AcquirePart().
  73.         <37>     5/30/95    CG        #1251234 Extraneous items in Paste As kind
  74.                                     popup.
  75.         <36>     5/26/95    VL        1251403: Multithreading naming support.
  76.         <35>     5/18/95    CG        #1249263 BB: BndNSUtl.cpp does not compile
  77.                                     standalone.
  78.         <34>      5/1/95    CG        #1240845    BB: Kinds popups need to include
  79.                                     all kinds that an editor can edit.
  80.         <33>     4/29/95    TÇ        1243222 BB: New documents from stationery
  81.                                     should have create/modinfo reset.
  82.         <32>     4/27/95    CC        1243348: Moved ShowAlert into
  83.                                     DlogUtils.cpp.
  84.                                     ShowLinkInfo: Don't alert user on break
  85.                                     link (problems with nested calls use
  86.                                     library resources).
  87.         <31>     4/25/95    CC        1242555: TranslateValueTypes: $5 entered as
  88.                                     bug 1242571.
  89.                                     1242555: ShowPasteAsDialog: $5 entered as
  90.                                     bug 1242581.
  91.                                     1242555:  OthersDlgFilterProc: Removed
  92.                                     obsolete $5 comment.
  93.         <30>     4/14/95    TÇ        #1235279 BB: InfoUtil & StdTypIO functions
  94.                                     should take Environment* and SU* when
  95.                                     possible
  96.         <29>     3/28/95    CC        1229640: Added LinkInfoFilterProc and
  97.                                     PasteAsFilterProc.
  98.                                     Added DeavtivateModalDialog routine.
  99.                                     DrawKindName and DrawEditorName calls
  100.                                     DrawITextInDlogBox utility.
  101.         <28>     3/27/95    CC        1229640: Use ODTranslation::
  102.                                     ShowTranslateDialog() in ShowPasteAsDialog.
  103.                                     Show editor in Paste As dialog.
  104.         <27>     3/22/95    CC        1230322: Changed parameter to
  105.                                     ShowPasteAsDialog(); removed
  106.                                     DefaultMergeSetting().
  107.         <26>     3/17/95    CC        1203315: Added DefaultMergeSetting(),
  108.                                     EnablePasteAsOkButton() and
  109.                                     DrawDeactivePICTItem().
  110.                                     Removed InitialMergeSetting() &
  111.                                     DrawDeactiveDialogItem().
  112.                                     Fix to PrepareToDrawGray to set the pen
  113.                                     pattern to gray if no gray color is
  114.                                     available.
  115.         <25>      3/9/95    CC        1221471: Added changesAllowed parameter to
  116.                                     ShowLinkDestinationInfo() and
  117.                                     ShowLinkSourceInfo().
  118.         <24>      3/9/95    CC        1220342: DrawIntlStaticText: Save and
  119.                                     restore font; don't change font if dialog
  120.                                     font is same script as intl text.
  121.                                     defined ODDisposeRoutineDescriptor and
  122.                                     ODDisposeDlg macros.
  123.                                     MakeOthersList(): don't set window font and
  124.                                     size; adopt font and size as determined by
  125.                                     'finf' resource.
  126.                                     ShowOthersDialog: removed okButtonEnabled.
  127.                                     Moved DrawDefaultButtonOutline to DlogUtils
  128.                                     and renamed.
  129.         <23>      3/7/95    CC        1226083: Removed SetKindText(); added
  130.                                     DrawIntlStaticText() and gKindName global.
  131.         <22>      3/6/95    jpa        Use dialog utilities (ODGetNewDialog,
  132.                                     ODDialogFilterProc) to make dlogs movable.
  133.                                     [1218957]
  134.         <21>      3/3/95    CC        1199186 Save and restore the current port
  135.                                     in ShowPasteAsDialog, ShowLinkSourceInfo,
  136.                                     and ShowLinkDestinationInfo.
  137.                                     1223607 Removed link size from info
  138.                                     dialogs;
  139.                                     GetBestKindAndSize->BestContentKind.
  140.                                     1224967 Time updated was incorrect.
  141.                                     1223861 Added ShowLinkStatusAlert().
  142.         <20>     2/24/95    jpa        Use ODNewRgn. [1220810]
  143.         <19>     2/24/95    CC        1220342: GetMenuStringForKind: Return
  144.                                     script code.
  145.                                     1220342: AddTranslationKindToMenu: Set
  146.                                     script code for menu item.
  147.                                     1220339: CreateTranslationStrings: Modified
  148.                                     to build StringWithScriptCodeArrayPtr.
  149.         <18>     2/15/95    CC        Lots of changes:
  150.                                     1194329 UpdateNow button in info dialogs is
  151.                                     enabled only if "Manually" is selected and
  152.                                     the link (or link destination) needs
  153.                                     updating.
  154.                                     1220318 Added LinkDialogFilter.
  155.                                     1220318 ShowLinkInfo -- Use
  156.                                     LinkDialogFilter in call to ModalDialog.
  157.                                     1205033 LinkInfo dialogs should be static
  158.                                     if draft is read-only
  159.                                     1218931 Link Info Dialog changes when draft
  160.                                     is read-only
  161.                                     1196831 Show link size in K bytes if 1K or
  162.                                     larger.
  163.                                     1220327 Data Interchange dialogs need to
  164.                                     use filter procs.
  165.                                     1153942    Changes to Destination Link Info
  166.                                     dialog
  167.         <17>      2/7/95    CC        1211295: Added GetOriginalDraft() and
  168.                                     SUClonedFromDraft().  ShowPasteAsDialog()
  169.                                     takes an isMove parameter.
  170.                                     1216124: ShowPasteAsDialog calls
  171.                                     ODWindowState::DeactivateFrontWindow() and
  172.                                     ActivateFrontWindow().
  173.         <16>     1/25/95    jpa        New ODIText format [1212619]
  174.         <15>     1/25/95    CC        1213198 ShowOthersDialog: Call LDispose
  175.                                     BEFORE disposing of the LDEF.
  176.                                     1213954 Initialize editor field of
  177.                                     ODPasteAsResult to kODNoEditor.
  178.         <14>     1/12/95    jpa        Don't use obsolete Toolbox names [1211211]
  179.         <13>     1/10/95    CC        1153930: Added translation dialog;
  180.                                     implemented new technique for dimming
  181.                                     inactive items in Paste As dialog.
  182.         <12>    11/17/94    CG        #1187128: Moved GetDestinationKindsList to
  183.                                     TransUtl.cpp to be shared with Part Info
  184.                                     and NoPart.
  185.         <11>    10/31/94    CG        #1147225: Moved ContentValueTypes to
  186.                                     InfoUtil.cpp.
  187.         <10>    10/27/94    CG        #1147225: Moved AddTypesToMenu to
  188.                                     InfoUtil.cpp.
  189.          <9>     10/7/94    CC        1160232 - Added calls to
  190.                                     EndUsingLibraryResources().
  191.          <8>     10/4/94    CC        1190299 - Use utility fcns in InfoUtil.h
  192.                                     and DlogUtil.h.
  193.          <7>     9/20/94    CC        1160232 - Added ShowLinkUpdateAlert()
  194.                                     1153930 - Added TranslateValueTypes() and
  195.                                     other mods to add translation choices to
  196.                                     Paste As dialog.
  197.          <6>     8/10/94    CC        1179943 - LinkInfo dialog functions take
  198.                                     ODBaseLink and ODBaseLinkSource parameters.
  199.          <5>      8/2/94    CC        #1178169 - ShowPasteAsDialog() takes
  200.                                     ODFacet* instead of ODFrame*.
  201.          <4>     7/31/94    CC        ShowLinkDestinationInfo - fix to display
  202.                                     dialog correctly.
  203.          <3>     7/27/94    CC        Allocate kindList (a SOM object) on the
  204.                                     heap, not the stack.
  205.          <2>      7/5/94    CC        Added typecasts of pascal strings for PPCC
  206.                                     compiler.
  207.          <1>     6/24/94    CC        first checked in
  208.          <0>     6/13/94    SV        SOMverted
  209.  
  210.         ------------------- CC ---- Converted to SOM
  211.  
  212.         <14>      6/1/94    CG        Changed to use new public binding object.
  213.         <13>     5/11/94    TÇ        #1162405 Removed explicit ASLM dependency
  214.                                     for using resources (missed a couple)
  215.         <12>     5/10/94    TÇ        #1162405 Removed explicit ASLM dependency
  216.                                     for using resources
  217.         <11>      5/9/94    MB        #1162181: Changes necessary to install MMM.
  218.         <10>      4/6/94    CC        XMPTypeInfo: Changed field "creationDate"
  219.                                     to "creationTime" and "modificationDate" to
  220.                                     "changeTime". (1154722)
  221.          <9>      4/4/94    CC        Convert from using XMPTypeSet to
  222.                                     XMPTypeList (1153046).
  223.          <8>      4/1/94    TÇ        #1154941: Get OpenDoc source to actually
  224.                                     compile for PowerPC
  225.          <7>     3/28/94    CG        1153547: Renamed XMPSessn.h to XMPSessM.h.
  226.          <6>     3/25/94    JA        Added missing #include (1147588)
  227.          <5>     3/25/94    eeh        bug #1153053: Changes for PPC nativity.
  228.          <4>     3/24/94    CC        ShowLinkSourceInfo() takes XMPUpdateID
  229.                                     parameter; XMPPasteAsResult specifies
  230.                                     original kind when selected kind is a
  231.                                     translation (1153068).
  232.          <3>     3/17/94    CC        Added ShowLinkSourceInfo() and
  233.                                     ShowLinkDestinationInfo(). (1151329)
  234.          <1>     3/14/94    CC        first checked in
  235.          <0>     3/14/94    CC        Create ShowPasteAsDialog (1144253).
  236.  
  237.     In Progress:
  238.         
  239. */
  240.  
  241. #ifndef _PLFMDEF_
  242. #include <plfmdef.h>
  243. #endif
  244.  
  245. #ifndef _LINKDLGS_
  246. #include <LinkDlgs.h>
  247. #endif
  248.  
  249. #ifndef _INFOUTIL_
  250. #include <InfoUtil.h>
  251. #endif
  252.  
  253. #ifndef _DLOGUTIL_
  254. #include <DlogUtil.h>
  255. #endif
  256.  
  257. #ifndef _EXCEPT_
  258. #include <Except.h>
  259. #endif
  260.  
  261. #ifndef _LINKDEFS_
  262. #include <LinkDefs.h>
  263. #endif
  264.  
  265. #ifndef _USERSRCM_
  266. #include <UseRsrcM.h>
  267. #endif
  268.  
  269. #ifndef SOM_Module_OpenDoc_StdProps_defined
  270. #include <StdProps.xh>
  271. #endif
  272.  
  273. #ifndef SOM_Module_OpenDoc_Foci_defined
  274. #include <Foci.xh>
  275. #endif
  276.  
  277. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  278. #include <StdTypes.xh>
  279. #endif
  280.  
  281. #ifndef SOM_ODTypeList_xh
  282. #include <TypeList.xh>
  283. #endif
  284.  
  285. #ifndef SOM_ODTypeListIterator_xh
  286. #include <TypLsItr.xh>
  287. #endif
  288.  
  289. #ifndef SOM_ODStorageUnit_xh
  290. #include <StorageU.xh>
  291. #endif
  292.  
  293. #ifndef SOM_ODPart_xh
  294. #include <Part.xh>
  295. #endif
  296.  
  297. #ifndef SOM_ODFrame_xh
  298. #include <Frame.xh>
  299. #endif
  300.  
  301. #ifndef SOM_ODFacet_xh
  302. #include <Facet.xh>
  303. #endif
  304.  
  305. #ifndef SOM_ODBaseLink_xh
  306. #include <LinkB.xh>
  307. #endif
  308.  
  309. #ifndef SOM_ODBaseLinkSource_xh
  310. #include <LinkSrcB.xh>
  311. #endif
  312.  
  313. #ifndef SOM_ODBinding_xh
  314. #include <ODBindng.xh>
  315. #endif
  316.  
  317. #ifndef SOM_ODTranslation_xh
  318. #include <Translt.xh>
  319. #endif
  320.  
  321. #ifndef SOM_ODWindowState_xh
  322. #include <WinStat.xh>
  323. #endif
  324.  
  325. #ifndef _BINDNGH_
  326. #include <BindngH.h>
  327. #endif
  328.  
  329. #ifndef _BNDNSUTL_
  330. #include <BndNSUtl.h>
  331. #endif
  332.  
  333. #ifndef SOM_ODSession_xh
  334. #include <ODSessn.xh>
  335. #endif
  336.  
  337. #ifndef SOM_ODArbitrator_xh
  338. #include <Arbitrat.xh>
  339. #endif
  340.  
  341. #ifndef SOM_ODDispatcher_xh
  342. #include <Disptch.xh>
  343. #endif
  344.  
  345. #ifndef _ODUTILS_
  346. #include <ODUtils.h>
  347. #endif
  348.  
  349. #ifndef _PASCLSTR_
  350. #include <PasclStr.h>
  351. #endif
  352.  
  353. #ifndef _ISOSTR_
  354. #include <ISOStr.h>
  355. #endif
  356.  
  357. #ifndef _DOCUTILS_
  358. #include <DocUtils.h>
  359. #endif
  360.  
  361. #ifndef _ODMEMORY_
  362. #include <ODMemory.h>
  363. #endif
  364.  
  365. #ifdef __SC__
  366. #ifndef __PACKAGES__
  367. #include <Packages.h>
  368. #endif
  369. #else
  370. #ifndef __TEXTUTILS__
  371. #include <TextUtils.h>
  372. #endif
  373. #endif
  374.  
  375. #ifndef __STRING__
  376. #include <String.h>
  377. #endif
  378.  
  379. #ifndef __GESTALTEQU__
  380. #include <GestaltEqu.h>
  381. #endif
  382.  
  383. #ifndef __DIALOGS__
  384. #include <Dialogs.h>
  385. #endif
  386.  
  387. #ifndef __TOOLUTILS__
  388. #include <ToolUtils.h>
  389. #endif
  390.  
  391. #ifndef __FONTS__
  392. #include <Fonts.h>
  393. #endif
  394.  
  395. #ifndef __CONTROLS__
  396. #include <Controls.h>
  397. #endif
  398.  
  399. #ifndef __RESOURCES__
  400. #include <Resources.h>
  401. #endif
  402.  
  403. #ifndef _TRANSUTL_
  404. #include <TransUtl.h>
  405. #endif
  406.  
  407. #ifndef __LISTS__
  408. #include <Lists.h>
  409. #endif
  410.  
  411. #ifndef __PALETTES__
  412. #include <Palettes.h>
  413. #endif
  414.  
  415. #ifndef _STORUTIL_
  416. #include <StorUtil.h>
  417. #endif
  418.  
  419. #ifndef _EDITRSET_
  420. #include <EditrSet.h>
  421. #endif
  422.  
  423. #ifndef _STDTYPIO_
  424. #include <StdTypIO.h>
  425. #endif
  426.  
  427. #ifndef _TEMPOBJ_
  428. #include <TempObj.h>
  429. #endif
  430.  
  431. #ifndef _ORDCOLL_
  432. #include "OrdColl.h"
  433. #endif
  434.  
  435. #ifndef SOM_ODStorageSystem_xh
  436. #include "ODStor.xh"
  437. #endif
  438.  
  439. #pragma segment Info
  440.  
  441. #if ODDebug
  442. #define ODDebugLinkDlgs 0
  443. #else
  444. #define ODDebugLinkDlgs 0
  445. #endif
  446.  
  447. //==============================================================================
  448. // Global variables
  449. //==============================================================================
  450.  
  451. // Use a global to pass the current session to the LinkFilterProc
  452. // Globals are per process, and there is only one session per process.
  453. static ODSession* gSession = kODNULL;
  454.  
  455. static ODName* gKindName = kODNULL;
  456. static ODName* gEditorName = kODNULL;
  457. static ODName* gEmbeddedEditorName = kODNULL;
  458.  
  459. //==============================================================================
  460. // Constants
  461. //==============================================================================
  462.  
  463. const Boolean kNoDefaultButton = kODFalse;
  464.  
  465. const short kButtonFrameInset = -4;
  466.  
  467. const short kControlInactive = 255;
  468. const short kControlActive = 0;
  469.  
  470. // Constants used in list manager calls
  471. const Boolean kDoDraw = true;
  472. const Boolean kNoGrow = false;
  473. const Boolean kIncludeScrollBar = true;
  474.  
  475. // Key codes
  476. // <eeh> moved to DlogUtil.h
  477. // const char kEnterKey        = 0x03;
  478. // const char kReturnKey        = 0x0D;
  479. // const char kEscapeKey        = 0x1B;
  480. // const char kUpArrowKey        = 0x1E;
  481. // const char kDownArrowKey    = 0x1F;
  482.  
  483. //==============================================================================
  484. // Scalar types
  485. //==============================================================================
  486. typedef char ODHandleState;
  487.  
  488. //==============================================================================
  489. // Function declarations
  490. //==============================================================================
  491. ODStatic void DisposeGlobalODNameAndZeroPtr(ODName** name);
  492.  
  493. ODStatic void SetDateTimeStrings(
  494.                     ODULong        dateTime,
  495.                     Str255        dateString, 
  496.                     Str255        timeString);
  497.  
  498. ODStatic void InitItemActive(
  499.                     DialogPtr    dlg,
  500.                     short        itemNumber,
  501.                     UserItemUPP    itemUPP,
  502.                     ODBoolean    itemActive);
  503.  
  504. ODStatic pascal void DrawDeactivePICTItem(DialogPtr theDialog, short theItem);
  505.  
  506. ODStatic ODBoolean DraftIsReadOnly(Environment* ev, ODStorageUnit* su);
  507.  
  508. ODStatic void SetControlActive(
  509.                     DialogPtr    dlg,
  510.                     short        itemNumber,
  511.                     ODBoolean    itemActive);
  512.  
  513. ODStatic ODType BestContentKind(ODStorageUnit* contentSU);
  514.  
  515. ODStatic pascal void DrawKindName(DialogPtr dialog, SInt16 item);
  516. ODStatic pascal void DrawEditorName(DialogPtr dialog, SInt16 item);
  517.  
  518. ODStatic void ResetEditorPopup(ODTypeList* kindList,
  519.                                 ODUShort kindIndex,
  520.                                 ODTypeList* translateToList,
  521.                                 ODUShort translateToIndex,
  522.                                 EditorSet* editorList,
  523.                                 MenuHandle editorMenu, 
  524.                                 ControlHandle popupCtlHndl, 
  525.                                 ODSession* session);
  526.  
  527. static pascal Boolean
  528. PasteAsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit);
  529.  
  530. ODStatic void SetPopupControlValue(ControlHandle popupControlHandle, short itemValue);
  531.  
  532. //------------------------------------------------------------------------------
  533. // DisposeGlobalODNameAndZeroPtr
  534. //------------------------------------------------------------------------------
  535. ODStatic void DisposeGlobalODNameAndZeroPtr(ODName** name)
  536. {
  537.     if (*name)
  538.     {
  539.         // simple way to force deletion of old name value without knowing
  540.         // that DisposeIText is the right way to destroy an ODName:
  541.         TempODName tempName = *name;
  542.         *name = kODNULL;
  543.     }
  544. }
  545.  
  546. //------------------------------------------------------------------------------
  547. // InitLinkDialogs
  548. //------------------------------------------------------------------------------
  549. void InitLinkDialogs(ODSession* session)
  550. {
  551.     gSession = session;
  552. }
  553.  
  554. //------------------------------------------------------------------------------
  555. // DrawEditorName
  556. //------------------------------------------------------------------------------
  557.  
  558. ODStatic pascal void DrawEditorName(DialogPtr dialog, SInt16 item)
  559. {
  560.     short            itemType;
  561.     Handle            itemHandle;
  562.     Rect            itemRect;
  563.  
  564.     GetDialogItem(dialog, item, &itemType, &itemHandle, &itemRect);
  565.  
  566.     if ( gEditorName )
  567.         DrawITextInDlogBox(gEditorName, &itemRect, dialog, kODTrue);
  568. }
  569.  
  570. //------------------------------------------------------------------------------
  571. // DrawEmbeddedEditorName
  572. //------------------------------------------------------------------------------
  573.  
  574. ODStatic pascal void DrawEmbeddedEditorName(DialogPtr dialog, SInt16 item)
  575. {
  576.     short            itemType;
  577.     Handle            itemHandle;
  578.     Rect            itemRect;
  579.  
  580.     GetDialogItem(dialog, item, &itemType, &itemHandle, &itemRect);
  581.  
  582.     if ( gEmbeddedEditorName )
  583.         DrawITextInDlogBox(gEmbeddedEditorName, &itemRect, dialog, kODTrue);
  584. }
  585.  
  586. //------------------------------------------------------------------------------
  587. // GetSelectedType
  588. //------------------------------------------------------------------------------
  589. // $$$$$ Should be replaced by GetThisKindFromList in InfoUtil.h
  590.  
  591. ODStatic ODType GetSelectedType(ODTypeList* typeList, ODSShort typeIndex)
  592. {
  593.     Environment*        ev = somGetGlobalEnvironment();
  594.     ODType                type = kODNULL;
  595.     ODTypeListIterator*    iter = typeList->CreateTypeListIterator(ev);
  596.     
  597.     for ( type = iter->First(ev); 
  598.           (--typeIndex > 0) && iter->IsNotComplete(ev); 
  599.           type = iter->Next(ev) )
  600.     {
  601.         ODDisposePtr(type);
  602.         type = kODNULL;
  603.     }
  604.  
  605.     delete iter;
  606.     
  607.     return type;
  608. }
  609.  
  610. //------------------------------------------------------------------------------
  611. // GetSelectedEditor
  612. //------------------------------------------------------------------------------
  613.  
  614. ODStatic ODEditor GetSelectedEditor(EditorSet* editorList, ODSShort editorIndex)
  615. {
  616.     ODEditor            editor;
  617.     EditorSetIterator*    iter = editorList->CreateIterator();
  618.     
  619.     for ( editor = iter->First(); 
  620.           (--editorIndex > 0) && iter->IsNotComplete(); 
  621.           editor = iter->Next() )
  622.     {
  623.     }
  624.  
  625.     delete iter;
  626.     
  627.     if ( editor != kODNULL )
  628.         editor = ODISOStrFromCStr((char *) editor);
  629.  
  630.     return editor;
  631. }
  632.  
  633. //------------------------------------------------------------------------------
  634. // EnableKindPopupItems
  635. //------------------------------------------------------------------------------
  636.  
  637. ODStatic void EnableKindPopupItems(
  638.                     ODBoolean            forMerge,
  639.                     ODTypeList*            typeList,
  640.                     ODTypeList*            translateList,
  641.                     ODSShort            translationIndex,
  642.                     MenuHandle            kindMenu,
  643.                     ODEditor            editor,
  644.                     ODNameSpaceManager*    nsm)
  645. {
  646.     Environment* ev = somGetGlobalEnvironment();
  647.  
  648.     ODUShort item = EnableTypesInMenu(typeList, kindMenu, forMerge ? editor : kODNULL, nsm);
  649.  
  650.     // If a translation choice is present in the popup, enable it if appropriate;
  651.     if ( translationIndex != 0 )
  652.     {
  653.         TempODType translationKind = GetSelectedType(translateList, translationIndex);
  654.  
  655.         if ( !forMerge || EditorSupportsKind(nsm, editor, translationKind) )
  656.             EnableItem(kindMenu, ++item);
  657.         else
  658.             DisableItem(kindMenu, ++item);
  659.     }
  660.  
  661.     // Enable the "Translate to…" item in the kind popup if translation is possible
  662.     if ( translateList->Count(ev) > 0 )
  663.         EnableItem(kindMenu, ++item);
  664.     else
  665.         DisableItem(kindMenu, ++item);
  666. }
  667.  
  668. //------------------------------------------------------------------------------
  669. // EnablePasteAsOkButton
  670. //------------------------------------------------------------------------------
  671.  
  672. ODStatic void EnablePasteAsOkButton(DialogPtr dlog, MenuHandle kindMenu)
  673. {
  674.     Environment*    ev = somGetGlobalEnvironment();
  675.     short            itemType;
  676.     Handle            itemHandle;
  677.     Rect            itemRect;
  678.     ODSShort        kindItemSelected;
  679.     ODBoolean        shouldBeEnabled;
  680.  
  681.     GetDialogItem(dlog, kPasteAsKindPopup, &itemType, &itemHandle, &itemRect);
  682.     ASSERT_CONTROL_ITEM(itemType);
  683.     kindItemSelected = (ODSShort) GetControlValue((ControlHandle)itemHandle);
  684.  
  685.     // Only the first 31 items of a menu may be disabled
  686.     if ( kindItemSelected > 31 )
  687.         shouldBeEnabled = kODTrue;
  688.     else
  689.         // BitTst numbers the bits hi to low
  690.         shouldBeEnabled = BitTst(&(**kindMenu).enableFlags, 31-kindItemSelected);
  691.  
  692.     EnableOkButton(dlog, shouldBeEnabled);
  693. }
  694.  
  695. //------------------------------------------------------------------------------
  696. // BestMergeKindSetting
  697. //------------------------------------------------------------------------------
  698.  
  699. ODStatic ODSShort BestMergeKindSetting(
  700.                     ODTypeList*            kinds,
  701.                     ODType                bestKind,
  702.                     ODEditor            editor,
  703.                     ODNameSpaceManager*    nsm)
  704. {
  705.     if ( bestKind && EditorSupportsKind(nsm, editor, bestKind) )
  706.         return IndexOfKindInList(kinds, bestKind);
  707.     
  708.     Environment*        ev = somGetGlobalEnvironment();
  709.     ODSShort            kindItem = 0;        // Default in case none are supported
  710.  
  711.     ODTypeListIterator*    iter = kinds->CreateTypeListIterator(ev);
  712.     
  713.     ODType                type;
  714.     ODSShort            i;
  715.     for ( type = iter->First(ev), i = 1; 
  716.           iter->IsNotComplete(ev); 
  717.           type = iter->Next(ev), ++i )
  718.     {
  719.         ODBoolean supports = EditorSupportsKind(nsm, editor, type);
  720.         ODDisposePtr(type);
  721.         if ( supports )
  722.         {
  723.             kindItem = i;
  724.             break;
  725.         }
  726.     }
  727.  
  728.     delete iter;
  729.     
  730.     return kindItem;
  731. }
  732.  
  733. //------------------------------------------------------------------------------
  734. // InitialViewSelection
  735. //------------------------------------------------------------------------------
  736. ODStatic void InitialViewSelection(DialogPtr dlg, ODTypeToken viewType, ODSession* session)
  737. {
  738.     short        itemType;
  739.     Handle        itemHandle;
  740.     Rect        itemRect;
  741.     ODSShort    viewItem;
  742.     
  743.     Environment* ev = somGetGlobalEnvironment();
  744.  
  745.     if (viewType == session->Tokenize(ev, kODViewAsFrame))
  746.         viewItem = kODPasteAsFrameMenuItem;
  747.     else if (viewType == session->Tokenize(ev, kODViewAsLargeIcon))
  748.         viewItem = kODPasteAsLargeIconMenuItem;
  749.     else if (viewType == session->Tokenize(ev, kODViewAsSmallIcon))
  750.         viewItem = kODPasteAsSmallIconMenuItem;
  751.     else if (viewType == session->Tokenize(ev, kODViewAsThumbnail))
  752.         viewItem = kODPasteAsThumbnailMenuItem;
  753.     else
  754.         viewItem = kODPasteAsFrameMenuItem;
  755.  
  756.     GetDialogItem(dlg, kPasteAsEmbedPopup, &itemType, &itemHandle, &itemRect);
  757.     ASSERT_CONTROL_ITEM(itemType);
  758.     SetControlValue((ControlHandle)itemHandle, viewItem);
  759. }
  760.  
  761. //------------------------------------------------------------------------------
  762. // GetViewSelected
  763. //------------------------------------------------------------------------------
  764. ODStatic ODTypeToken GetViewSelected(DialogPtr dlg, ODSession* session)
  765. {
  766.     short        itemType;
  767.     Handle        itemHandle;
  768.     Rect        itemRect;
  769.  
  770.     Environment* ev = somGetGlobalEnvironment();
  771.  
  772.     GetDialogItem(dlg, kPasteAsEmbedPopup, &itemType, &itemHandle, &itemRect);
  773.     ASSERT_CONTROL_ITEM(itemType);
  774.     ODSShort viewItem = (ODSShort) GetControlValue((ControlHandle)itemHandle);
  775.     ODType viewAs;
  776.     switch ( viewItem )
  777.     {
  778.     case kODPasteAsLargeIconMenuItem:
  779.             viewAs = kODViewAsLargeIcon;
  780.             break;
  781.     case kODPasteAsSmallIconMenuItem:
  782.             viewAs = kODViewAsSmallIcon;
  783.             break;
  784.     case kODPasteAsThumbnailMenuItem:
  785.             viewAs = kODViewAsThumbnail;
  786.             break;
  787.     default:
  788.             viewAs = kODViewAsFrame;
  789.             break;
  790.     }
  791.  
  792.     return session->Tokenize(ev, viewAs);
  793. }
  794.  
  795. //------------------------------------------------------------------------------
  796. // HaveColorQuickdraw
  797. //------------------------------------------------------------------------------
  798. ODStatic ODBoolean HaveColorQuickdraw()
  799. {
  800.     long response;
  801.  
  802.     Gestalt(gestaltQuickdrawFeatures, &response);
  803.         
  804.     /* check if Color QuickDraw is available */    
  805.     return BitTst(&response, 31-gestaltHasColor);
  806. }
  807.  
  808. //------------------------------------------------------------------------------
  809. // EnableDialogItem
  810. //------------------------------------------------------------------------------
  811. ODStatic void EnableDialogItem(DialogPtr dlg, short itemNumber, ODBoolean enable)
  812. {
  813.     short        itemType;
  814.     Handle        itemHandle;
  815.     Rect        itemRect;
  816.  
  817.     GetDialogItem(dlg, itemNumber, &itemType, &itemHandle, &itemRect);
  818.     if ( enable )
  819.         itemType &= ~itemDisable;
  820.     else
  821.         itemType |= itemDisable;
  822.     SetDialogItem(dlg, itemNumber, itemType, itemHandle, &itemRect);
  823. }
  824.  
  825. //------------------------------------------------------------------------------
  826. // InvalDialogItem
  827. //------------------------------------------------------------------------------
  828. ODStatic void InvalDialogItem(DialogPtr dlg, short itemNumber)
  829. {
  830.     short        itemType;
  831.     Handle        itemHandle;
  832.     Rect        itemRect;
  833.     WindowPtr    savePort;
  834.  
  835.     GetPort(&savePort);
  836.     SetPort(dlg);
  837.     GetDialogItem(dlg, itemNumber, &itemType, &itemHandle, &itemRect);    
  838.     InvalRect(&itemRect);
  839.     SetPort(savePort);
  840. }
  841.  
  842. //------------------------------------------------------------------------------
  843. // SetPopupControlValue
  844. //------------------------------------------------------------------------------
  845. ODStatic void SetPopupControlValue(ControlHandle popupControlHandle, short itemValue)
  846. {
  847.     // The resource file must be in the chain in order for the popup to redraw.
  848.     CUsingLibraryResources r;
  849.     SetControlValue(popupControlHandle, itemValue);
  850. }
  851.  
  852. //------------------------------------------------------------------------------
  853. // SetupControlItem
  854. //------------------------------------------------------------------------------
  855. ODStatic void SetupControlItem(
  856.                     DialogPtr    dlg,
  857.                     short        itemNumber,
  858.                     short        itemValue,
  859.                     ODBoolean    itemActive)
  860. {
  861.     short        itemType;
  862.     Handle        itemHandle;
  863.     Rect        itemRect;
  864.  
  865.     GetDialogItem(dlg, itemNumber, &itemType, &itemHandle, &itemRect);
  866.     ASSERT_CONTROL_ITEM(itemType);
  867.     SetControlValue((ControlHandle)itemHandle, itemActive? itemValue : 0);
  868.     HiliteControl((ControlHandle)itemHandle, itemActive ? kControlActive : kControlInactive);
  869. }
  870.  
  871. //------------------------------------------------------------------------------
  872. // InactivateEmbedAsPopup
  873. //------------------------------------------------------------------------------
  874.  
  875. ODStatic void InactivateEmbedAsPopup(DialogPtr dlg)
  876. // Set clipping to just the display area of the popup so the radio button
  877. // label isn't dimmed.
  878. {
  879.     short        aItem;
  880.     Handle        aHandle;
  881.     Handle        embedPopupCntlHandle;
  882.     Rect        aRect;
  883.     RgnHandle    embedTextRgn = ODNewRgn();
  884.     RgnHandle    embedPopupRgn = ODNewRgn();
  885.     RgnHandle    clipRgn = ODNewRgn();
  886.  
  887.     GetDialogItem(dlg, kPasteAsEmbedRadioBtn, &aItem, &aHandle, &aRect);
  888.     RectRgn(embedTextRgn,&aRect);
  889.  
  890.     GetDialogItem(dlg, kPasteAsEmbedPopup, &aItem, &embedPopupCntlHandle, &aRect);
  891.     RectRgn(embedPopupRgn,&aRect);
  892.  
  893.     GetClip(clipRgn);
  894.     DiffRgn(embedPopupRgn, embedTextRgn, embedPopupRgn);
  895.     SetClip(embedPopupRgn);
  896.     HiliteControl((ControlHandle)embedPopupCntlHandle, kControlInactive);
  897.     SetClip(clipRgn);
  898.     
  899.     ODDisposeHandle((Handle)clipRgn);
  900.     ODDisposeHandle((Handle)embedPopupRgn);
  901.     ODDisposeHandle((Handle)embedTextRgn);
  902. }
  903.  
  904. //------------------------------------------------------------------------------
  905. // ClipOutRect
  906. //------------------------------------------------------------------------------
  907.  
  908. ODStatic RgnHandle ClipOutRect(Rect* r)
  909. {
  910.     RgnHandle    saveRgn = ODNewRgn();
  911.     RgnHandle    rectRgn = ODNewRgn();
  912.     RgnHandle    clipRgn = ODNewRgn();
  913.  
  914.     GetClip(saveRgn);
  915.  
  916.     RectRgn(rectRgn, r);
  917.  
  918.     GetClip(clipRgn);
  919.     DiffRgn(clipRgn, rectRgn, clipRgn);
  920.     SetClip(clipRgn);
  921.  
  922.     ODDisposeHandle((Handle)rectRgn);
  923.     ODDisposeHandle((Handle)clipRgn);
  924.     
  925.     return saveRgn;
  926. }
  927.  
  928. //------------------------------------------------------------------------------
  929. // SetAutomaticUpdateControls
  930. //------------------------------------------------------------------------------
  931. ODStatic void SetAutomaticUpdateControls(DialogPtr dlg, ODBoolean autoUpdateSetting)
  932. {
  933.     short    itemType;
  934.     Handle    itemHandle;
  935.     Rect    itemRect;
  936.  
  937.     GetDialogItem(dlg, kPasteAsAutomaticRadioBtn, &itemType, &itemHandle, &itemRect);
  938.     ASSERT_CONTROL_ITEM(itemType);
  939.     SetControlValue((ControlHandle)itemHandle, autoUpdateSetting);
  940.     GetDialogItem(dlg, kPasteAsManualRadioBtn, &itemType, &itemHandle, &itemRect);
  941.     ASSERT_CONTROL_ITEM(itemType);
  942.     SetControlValue((ControlHandle)itemHandle, !autoUpdateSetting);
  943. }
  944.  
  945. //------------------------------------------------------------------------------
  946. // SetMergeEmbedControls
  947. //------------------------------------------------------------------------------
  948. ODStatic void SetMergeEmbedControls(DialogPtr dlg, ODBoolean mergeSetting)
  949. {
  950.     short    itemType;
  951.     Handle    itemHandle;
  952.     Rect    itemRect;
  953.  
  954.     CUsingLibraryResources r;    // Necessary to change embed popup
  955.  
  956.     GetDialogItem(dlg, kPasteAsMergeRadioBtn, &itemType, &itemHandle, &itemRect);
  957.     ASSERT_CONTROL_ITEM(itemType);
  958.     SetControlValue((ControlHandle)itemHandle, mergeSetting);
  959.     
  960.     GetDialogItem(dlg, kPasteAsEmbedRadioBtn, &itemType, &itemHandle, &itemRect);
  961.     ASSERT_CONTROL_ITEM(itemType);
  962.     SetControlValue((ControlHandle)itemHandle, !mergeSetting);
  963.  
  964.     if ( mergeSetting )
  965.     {
  966.         InactivateEmbedAsPopup(dlg);
  967.     }
  968.     else
  969.     {
  970.         GetDialogItem(dlg, kPasteAsEmbedPopup, &itemType, &itemHandle, &itemRect);
  971.         ASSERT_CONTROL_ITEM(itemType);
  972.         HiliteControl((ControlHandle)itemHandle, kControlActive);
  973.     }
  974. }
  975.  
  976. //------------------------------------------------------------------------------
  977. // GetIndexedElement
  978. //------------------------------------------------------------------------------
  979.  
  980. ODStatic ODULong GetIndexedElement(OrderedCollection* translateFromList, ODULong translationIndex)
  981. {
  982.     OrderedCollectionIterator* oci = translateFromList->CreateIterator();
  983.  
  984.     ODULong elem = 0;
  985.  
  986.     for (    elem = (ODULong) oci->First();
  987.             oci->IsNotComplete(); 
  988.             elem = (ODULong) oci->Next() )
  989.     {
  990.         if ( --translationIndex == 0 )
  991.             break;
  992.     }
  993.  
  994.     ODDeleteObject(oci);
  995.  
  996.     return elem;
  997. }
  998.  
  999. //------------------------------------------------------------------------------
  1000. // GetOriginalDraft
  1001. //------------------------------------------------------------------------------
  1002. // Returns 0 if the original draft is unknown.  This is the case when content
  1003. // was placed in the draft without cloning.  This code is dependent on properties
  1004. // created by the argument storage unit's container suite.
  1005.  
  1006.  
  1007. static ODULong GetOriginalDraft(Environment* ev, ODDraft* draft)
  1008. {
  1009.     TempODStorageUnit    draftProperties = draft->AcquireDraftProperties(ev);
  1010.     return ODGetULongProp(ev, draftProperties, kODPropOriginalDraft, kODULong);
  1011. }
  1012.  
  1013. //------------------------------------------------------------------------------
  1014. // SUClonedFromDraft
  1015. //------------------------------------------------------------------------------
  1016. // Returns kODTrue is the argument storage unit is the clone of a storage unit
  1017. // from the argument draft.  This code is dependent on properties created by
  1018. // the argument storage unit's container suite.
  1019.  
  1020. static ODBoolean SUClonedFromDraft(Environment* ev,
  1021.             ODStorageUnit* su,
  1022.             ODDraft* draft)
  1023. {
  1024.     return ((ODDraft*)GetOriginalDraft(ev, su->GetDraft(ev)) == draft &&
  1025.             su->Exists(ev, kODPropOriginalID, kODULong, 0));
  1026. }
  1027.  
  1028. //------------------------------------------------------------------------------
  1029. // DeactivateModalDialog
  1030. //------------------------------------------------------------------------------
  1031.  
  1032. ODStatic void DeactivateModalDialog(ModalFilterUPP filterProc)
  1033. {
  1034.     DialogPtr dialog = (DialogPtr) FrontWindow();
  1035.  
  1036.     if ( dialog )
  1037.     {
  1038.         EventRecord event;
  1039.         
  1040.         event.what = activateEvt;
  1041.         event.message = (long) dialog;
  1042.         event.modifiers = 0;
  1043.  
  1044.         CallModalFilterProc(filterProc, dialog, &event, 0);
  1045.     }
  1046. }
  1047.  
  1048. //------------------------------------------------------------------------------
  1049. // PasteAsFilterProc
  1050. //------------------------------------------------------------------------------
  1051.  
  1052. static pascal Boolean
  1053. PasteAsFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit)
  1054. {    
  1055.     // If the event is a deactivate event, the ok button must be deactivated
  1056.     // before the surrounding outline is drawn so it is drawn dim.
  1057.     ODBoolean rslt = ODButtonKeyFilterProc(dialog,event,itemHit);
  1058.  
  1059.     if ( event->what == activateEvt )
  1060.     {
  1061.         ODOutlineDefaultButtonDrawProc(dialog, kPasteAsDefaultButtonItem);
  1062.     }
  1063.  
  1064.     return rslt;
  1065. }
  1066.  
  1067. //------------------------------------------------------------------------------
  1068. // ShowPasteAsDialog
  1069. //------------------------------------------------------------------------------
  1070.  
  1071. ODBoolean ShowPasteAsDialog(
  1072.                 ODBoolean                canPasteLink,
  1073.                 ODPasteAsMergeSetting    mergeSetting,
  1074.                 ODBoolean                isMove,
  1075.                 ODStorageUnit*            contentSU,
  1076.                 ODFacet*                facet,
  1077.                 ODTypeToken                viewType,
  1078.                 ODPasteAsResult*        result)
  1079.  
  1080. {
  1081.     Environment* ev = somGetGlobalEnvironment();
  1082.  
  1083.     WindowPtr    savePort;                            ODVolatile(savePort);
  1084.     GetPort(&savePort);
  1085.  
  1086.     short          itemHit = kPasteAsCancelBtn;
  1087.     short        itemType;
  1088.     DialogPtr      dlg = kODNULL;                        ODVolatile(dlg);
  1089.     Handle        itemHandle;
  1090.     Rect        itemRect;
  1091.     Rect        kindPopupRect;
  1092.     Rect        editorPopupRect;
  1093.     short        kindItemSelected;
  1094.     short        kindItemOthers;
  1095.     short        kindItemCurrent;
  1096.     ODBoolean    kindPopupHasNoTranslationKind = kODTrue;
  1097.     ODUShort    translationIndex = 0;
  1098.  
  1099.     ODSLong        refSaved;
  1100.     OSErr        resErr;
  1101.  
  1102.     ODBoolean    userChangedKind = kODFalse;
  1103.  
  1104.     ControlHandle kindPopupControlHandle;
  1105.     ControlHandle editorPopupControlHandle;
  1106.  
  1107.     ODEditor mergeEditorID = kODNULL;                ODVolatile(mergeEditorID);
  1108.     ODEditor embedEditorID = kODNULL;                ODVolatile(embedEditorID);
  1109.     ODEditor preferredEditorID = kODNULL;            ODVolatile(preferredEditorID);
  1110.  
  1111.     EditorSet* editorList = kODNULL;                ODVolatile(editorList);
  1112.  
  1113.     ODSShort bestKindIndex = 1;
  1114.     ODSShort bestMergeKind = 1;
  1115.  
  1116.     ODType bestKind = kODNULL;                        ODVolatile(bestKind);
  1117.     ODTypeList*    kindList = kODNULL;                    ODVolatile(kindList);
  1118.     ODTypeList*    translateToList = kODNULL;            ODVolatile(translateToList);
  1119.     OrderedCollection* translateFromList = kODNULL;    ODVolatile(translateFromList);
  1120.  
  1121.     MenuHandle kindMenu = kODNULL;                    ODVolatile(kindMenu);
  1122.     MenuHandle editorMenu = kODNULL;                ODVolatile(editorMenu);
  1123.  
  1124.     UserItemUPP DrawBoxItemUPP = kODNULL;            ODVolatile(DrawBoxItemUPP);
  1125.     UserItemUPP DrawDeactiveItemUPP = kODNULL;        ODVolatile(DrawDeactiveItemUPP);
  1126.     UserItemUPP    DrawEditorNameUPP = kODNULL;        ODVolatile(DrawEditorNameUPP);
  1127.     UserItemUPP    DrawEmbeddedEditorNameUPP = kODNULL;ODVolatile(DrawEmbeddedEditorNameUPP);
  1128.     UserItemUPP    DrawKindNameUPP = kODNULL;            ODVolatile(DrawKindNameUPP);
  1129.  
  1130.     ModalFilterUPP modalFilter = kODNULL;            ODVolatile(modalFilter);
  1131.  
  1132.     if ( canPasteLink )
  1133.         canPasteLink = contentSU->Exists(ev, kODPropLinkSpec, (ODValueType) kODLinkSpec, 0);
  1134.  
  1135.     result->pasteLinkSetting = (!isMove) && canPasteLink;
  1136.     result->autoUpdateSetting = kODTrue;
  1137.     result->selectedKind = (ODType) kODNULL;
  1138.     result->translateKind = (ODType) kODNULL;
  1139.     result->editor = kODNoEditor;
  1140.  
  1141.     ODSession* session;
  1142.     {
  1143.         TempODPart part = facet->GetFrame(ev)->AcquirePart(ev);
  1144.         session = part->GetStorageUnit(ev)->GetSession(ev);
  1145.     }
  1146.  
  1147.     TRY
  1148.         ODBinding* binding = session->GetBinding(ev);
  1149.         ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
  1150.  
  1151.         session->GetWindowState(ev)->DeactivateFrontWindows(ev);
  1152.  
  1153.         { TempODPart part = facet->GetFrame(ev)->AcquirePart(ev);
  1154.           mergeEditorID = GetCurrentEditorForPart(part);
  1155.         }
  1156.         
  1157.         kindList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  1158.         ContentValueTypes(contentSU, kindList);
  1159.         
  1160.         // Now get all possible translations from the available kinds
  1161.         translateToList = session->GetStorageSystem(ev)->CreateTypeList(ev, (ODTypeList*) kODNULL);
  1162.         translateFromList = new OrderedCollection;
  1163.         TranslateValueTypes(kindList, translateToList, translateFromList, session);
  1164.         
  1165.         refSaved = BeginUsingLibraryResources();
  1166.         kindMenu = GetMenu(kPasteAsKindPopupMenu);
  1167.         resErr = ResError();
  1168.         EndUsingLibraryResources(refSaved);
  1169.         THROW_IF_NULL(kindMenu, resErr ? resErr : resNotFound);
  1170.     
  1171.         AddTypesToMenu(kindList, kindMenu, session);
  1172.         kindItemOthers = kindList->Count(ev) + 1;
  1173.  
  1174.         ODBoolean canMerge = (mergeSetting != kODPasteAsEmbedOnly);
  1175.         ODBoolean canEmbed = (mergeSetting != kODPasteAsMergeOnly);
  1176.  
  1177.         result->mergeSetting = (mergeSetting == kODPasteAsMerge) || (mergeSetting == kODPasteAsMergeOnly);
  1178.  
  1179.         {
  1180.             CUsingLibraryResources r;
  1181.             dlg = ODGetNewDialog(ev, kPasteAsDlgID, session, kNoDefaultButton);
  1182.             THROW_IF_NULL(dlg);
  1183.             SetPort(dlg);
  1184.             SetDialogTextStyle(dlg, kPasteAsDlgID, smCurrentScript);
  1185.         }
  1186.     
  1187.         /* Horizontal line needs to be drawn */
  1188.         GetDialogItem(dlg, kPasteAsHorizSep, &itemHit, &itemHandle, &itemRect);
  1189.         DrawBoxItemUPP = NewUserItemProc(DrawGrayBoxItem);
  1190.         SetDialogItem(dlg, kPasteAsHorizSep, itemHit, (Handle)DrawBoxItemUPP, &itemRect);
  1191.     
  1192.         // Set the draw routine for the default button outline item
  1193.         GetDialogItem(dlg, kPasteAsDefaultButtonItem, &itemHit, &itemHandle, &itemRect);
  1194.         SetDialogItem(dlg, kPasteAsDefaultButtonItem, itemHit, (Handle)GetODOutlineDefaultButtonDrawProc(), &itemRect);
  1195.         
  1196.         // Create one UPP for all user items used to draw deactive PICTs
  1197.         DrawDeactiveItemUPP = NewUserItemProc(DrawDeactivePICTItem);
  1198.  
  1199.         // Initialize state of "Paste with Link" checkbox and label
  1200.         SetupControlItem(dlg, kPasteAsLinkCheckbox, result->pasteLinkSetting, canPasteLink);
  1201.         
  1202.         // Initialize state of "Get Updates" radio buttons and labels
  1203.         if ( result->pasteLinkSetting)
  1204.             HideDialogItem(dlg, kPasteAsUpdateDisabledText);
  1205.         else
  1206.             HideDialogItem(dlg, kPasteAsUpdateText);
  1207.  
  1208.         SetupControlItem(dlg, kPasteAsAutomaticRadioBtn, result->autoUpdateSetting, result->pasteLinkSetting);
  1209.         SetupControlItem(dlg, kPasteAsManualRadioBtn, !result->autoUpdateSetting, result->pasteLinkSetting);
  1210.  
  1211.         // set up merge picture, radio button, and label
  1212.         InitItemActive(dlg, kPasteAsMergePict, DrawDeactiveItemUPP, canMerge);
  1213.         SetupControlItem(dlg, kPasteAsMergeRadioBtn, result->mergeSetting, canMerge);
  1214.  
  1215.         // set up embed picture, radio button, and label
  1216.         InitItemActive(dlg, kPasteAsEmbedPict, DrawDeactiveItemUPP, canEmbed);
  1217.         SetupControlItem(dlg, kPasteAsEmbedRadioBtn, !result->mergeSetting, canEmbed);
  1218.     
  1219.         // set up initial "Paste as:" popup selection
  1220.         InitialViewSelection(dlg, viewType, session);
  1221.  
  1222.         // inactivate the "Embed as:" popup if merge is initially selected
  1223.         if ( result->mergeSetting )
  1224.         {
  1225.             GetDialogItem(dlg, kPasteAsEmbedPopup, &itemType, &itemHandle, &itemRect);
  1226.             ASSERT_CONTROL_ITEM(itemType);
  1227.             HiliteControl((ControlHandle)itemHandle, kControlInactive);
  1228.         }
  1229.  
  1230.         // Determine the indices of the best kind and the best kind that can be merged
  1231.         bestKind = BestContentKind(contentSU);
  1232.         if ( bestKind )
  1233.             bestKindIndex = IndexOfKindInList(kindList, bestKind);
  1234.         if ( bestKindIndex == 0 )    // In case preferred kind property is bogus
  1235.             bestKindIndex = 1;
  1236.  
  1237.         bestMergeKind = BestMergeKindSetting(kindList, bestKind, mergeEditorID, nsm);
  1238.  
  1239.         // Suppress the preferred editor if it doesn't support the preferred kind
  1240.         preferredEditorID = ODGetISOStrProp(ev, contentSU, kODPropPreferredEditor, kODEditor, kODNULL, kODNULL);
  1241.         if ( preferredEditorID && bestKind && !EditorSupportsKind(nsm, preferredEditorID, bestKind) )
  1242.         {
  1243.             ODDisposePtr((ODPtr) preferredEditorID);
  1244.             preferredEditorID = kODNULL;
  1245.         }
  1246.  
  1247. #if ODDebugLinkDlgs
  1248.         somPrintf("ShowPasteAsDialog: mergeSetting = %u, best merge kind = %u\n", mergeSetting, (bestMergeKind != 0));
  1249. #endif
  1250.  
  1251.         // Set up the Kind popup items
  1252.         EnableKindPopupItems(result->mergeSetting, kindList, translateToList, 0, kindMenu, mergeEditorID, nsm);
  1253.         GetDialogItem(dlg, kPasteAsKindPopup, &itemType, (Handle*) &kindPopupControlHandle, &kindPopupRect);
  1254.         ASSERT_CONTROL_ITEM(itemType);
  1255.         SetControlValue(kindPopupControlHandle, result->mergeSetting ? bestMergeKind : bestKindIndex);
  1256.     
  1257.         // Determine if the root storage unit is an existing part from the same draft
  1258.         // as the pasting part
  1259.  
  1260.         ODDraft* partDraft;
  1261.         // Get the draft from the part, not the frame, because the frame's storage
  1262.         // unit is null if non-persistent.
  1263.         {
  1264.             TempODPart part = facet->GetFrame(ev)->AcquirePart(ev);
  1265.             partDraft = part->GetStorageUnit(ev)->GetDraft(ev);
  1266.         }
  1267.         ODBoolean contentIsPart = SUClonedFromDraft(ev, contentSU, partDraft);
  1268.  
  1269.         // Set text of static "Kind:" label
  1270.         DisposeGlobalODNameAndZeroPtr(&gKindName);
  1271.         if ( bestKind && GetUserKindFromKind(nsm, bestKind, &gKindName) )
  1272.         {
  1273.             GetDialogItem(dlg, kPasteAsKindText, &itemType, &itemHandle, &itemRect);
  1274.             DrawKindNameUPP = NewUserItemProc(DrawKindName);
  1275.             SetDialogItem(dlg, kPasteAsKindText, userItem+itemDisable, (Handle) DrawKindNameUPP, &itemRect);
  1276.         }
  1277.  
  1278.         // inactivate the "Kind:" popup if embedding is initially selected, the operation is
  1279.         // a move, and a cloned part is in the storage unit (not intrinsic content).
  1280.         if ( (!result->mergeSetting) && isMove && contentIsPart )
  1281.         {
  1282.             HideDialogItem(dlg, kPasteAsKindPopup);
  1283.         }
  1284.         else
  1285.         {
  1286.             HideDialogItem(dlg, kPasteAsKindLabel);
  1287.             HideDialogItem(dlg, kPasteAsKindText);
  1288.         }
  1289.  
  1290.         // Setup the static text for the merge editor
  1291.         DisposeGlobalODNameAndZeroPtr(&gEditorName);
  1292.         if ( mergeEditorID && GetUserEditorFromEditor(nsm, mergeEditorID, &gEditorName) )
  1293.         {
  1294.             GetDialogItem(dlg, kPasteAsEditorText, &itemType, &itemHandle, &itemRect);
  1295.             DrawEditorNameUPP = NewUserItemProc(DrawEditorName);
  1296.             SetDialogItem(dlg, kPasteAsEditorText, userItem+itemDisable, (Handle) DrawEditorNameUPP, &itemRect);
  1297.         }
  1298.  
  1299.         // Setup the static text for the embedding editor
  1300.         // Since the contentSU will not be cloned during a move in the same document, this is a guess as to the
  1301.         // editor actually bound to the moved frame.
  1302.         if ( preferredEditorID )
  1303.             embedEditorID = ODISOStrFromCStr((char *) preferredEditorID);
  1304.         else
  1305.             embedEditorID = binding->ChooseEditorForPart(ev, contentSU, bestKind);
  1306.         
  1307.         DisposeGlobalODNameAndZeroPtr(&gEmbeddedEditorName);
  1308.         if ( embedEditorID && GetUserEditorFromEditor(nsm, embedEditorID, &gEmbeddedEditorName) )
  1309.         {
  1310.             GetDialogItem(dlg, kPasteAsEmbedEditorText, &itemType, &itemHandle, &itemRect);
  1311.             DrawEmbeddedEditorNameUPP = NewUserItemProc(DrawEmbeddedEditorName);
  1312.             SetDialogItem(dlg, kPasteAsEmbedEditorText, userItem+itemDisable, (Handle) DrawEmbeddedEditorNameUPP, &itemRect);
  1313.         }
  1314.  
  1315.         // Setup the editor popup
  1316.         editorList = new EditorSet;
  1317.         editorList->InitEditorSet();
  1318.  
  1319.         refSaved = BeginUsingLibraryResources();
  1320.         editorMenu = GetMenu(kPasteAsEditorPopupMenu);
  1321.         resErr = ResError();
  1322.         EndUsingLibraryResources(refSaved);
  1323.         THROW_IF_NULL(editorMenu, resErr ? resErr : resNotFound);
  1324.  
  1325.         GetDialogItem(dlg, kPasteAsEditorPopup, &itemType, (Handle*) &editorPopupControlHandle, &editorPopupRect);
  1326.         SetupEditorMenu(bestKind, editorList, editorMenu, editorPopupControlHandle, session);
  1327.  
  1328.         if ( result->mergeSetting )
  1329.         {
  1330.             HideDialogItem(dlg, kPasteAsEditorPopup);
  1331.             HideDialogItem(dlg, kPasteAsEmbedEditorText);
  1332.         }
  1333.         else if ( isMove && contentIsPart )
  1334.         {
  1335.             HideDialogItem(dlg, kPasteAsEditorPopup);
  1336.             HideDialogItem(dlg, kPasteAsEditorText);
  1337.         }
  1338.         else
  1339.         {
  1340.             HideDialogItem(dlg, kPasteAsEditorLabel);
  1341.             HideDialogItem(dlg, kPasteAsEmbedEditorText);
  1342.             HideDialogItem(dlg, kPasteAsEditorText);
  1343.         }
  1344.         
  1345.         modalFilter = NewModalFilterProc(PasteAsFilterProc);
  1346.  
  1347.         // Display the dialog
  1348.         ShowWindow(dlg);
  1349.     
  1350.         do {
  1351.             // Remember the currently selected kind
  1352.             kindItemCurrent = (ODSShort) GetControlValue(kindPopupControlHandle);
  1353.  
  1354.             {    CUsingLibraryResources r;
  1355.                 ModalDialog(modalFilter, &itemHit);
  1356.             }
  1357.     
  1358.             switch (itemHit)
  1359.             {
  1360.             case kPasteAsLinkCheckbox:
  1361.                     result->pasteLinkSetting = !result->pasteLinkSetting;
  1362.                     GetDialogItem(dlg, itemHit, &itemType, &itemHandle, &itemRect);
  1363.                     ASSERT_CONTROL_ITEM(itemType);
  1364.                     SetControlValue((ControlHandle)itemHandle, result->pasteLinkSetting);
  1365.  
  1366.                     if ( result->pasteLinkSetting )
  1367.                     {
  1368.                         GetDialogItem(dlg, kPasteAsUpdateDisabledText, &itemType, &itemHandle, &itemRect);
  1369.                         itemRect.left += 16384;
  1370.                         itemRect.right += 16384;
  1371.                         SetDialogItem(dlg, kPasteAsUpdateDisabledText, itemType, itemHandle, &itemRect);
  1372.                         ShowDialogItem(dlg, kPasteAsUpdateText);
  1373.                     }
  1374.                     else
  1375.                     {
  1376.                         GetDialogItem(dlg, kPasteAsUpdateText, &itemType, &itemHandle, &itemRect);
  1377.                         itemRect.left += 16384;
  1378.                         itemRect.right += 16384;
  1379.                         SetDialogItem(dlg, kPasteAsUpdateText, itemType, itemHandle, &itemRect);
  1380.                         ShowDialogItem(dlg, kPasteAsUpdateDisabledText);
  1381.                     }
  1382.  
  1383.                     SetupControlItem(dlg, kPasteAsAutomaticRadioBtn, result->autoUpdateSetting, result->pasteLinkSetting);
  1384.                     SetupControlItem(dlg, kPasteAsManualRadioBtn, !result->autoUpdateSetting, result->pasteLinkSetting);
  1385.                     break;
  1386.     
  1387.             case kPasteAsAutomaticRadioBtn:
  1388.                     result->autoUpdateSetting = kODTrue;
  1389.                     SetAutomaticUpdateControls(dlg, result->autoUpdateSetting);
  1390.                     break;
  1391.     
  1392.             case kPasteAsManualRadioBtn:
  1393.                     result->autoUpdateSetting = kODFalse;
  1394.                     SetAutomaticUpdateControls(dlg, result->autoUpdateSetting);
  1395.                     break;
  1396.     
  1397.             case kPasteAsMergePict:
  1398.             case kPasteAsMergeRadioBtn:
  1399.                     if ( !result->mergeSetting )
  1400.                     {
  1401.                         result->mergeSetting = kODTrue;
  1402.                         SetMergeEmbedControls(dlg, result->mergeSetting);
  1403.  
  1404.                         TempODType selectedKind = kODNULL;
  1405.                         if ( kindItemCurrent <= kindList->Count(ev) )
  1406.                             selectedKind = GetSelectedType(kindList, kindItemCurrent);
  1407.                         else
  1408.                             selectedKind = GetSelectedType(translateToList, translationIndex);
  1409.  
  1410.                         if ( !EditorSupportsKind(nsm, mergeEditorID, selectedKind) )
  1411.                         {
  1412.                             SetPopupControlValue(kindPopupControlHandle, bestMergeKind);
  1413.                             userChangedKind = kODFalse;    // Allow embed to automatically select best kind
  1414.                         }
  1415.  
  1416.                         EnableKindPopupItems(result->mergeSetting, kindList, translateToList, translationIndex, kindMenu, mergeEditorID, nsm);
  1417.     
  1418.                         if ( isMove && contentIsPart )
  1419.                         {
  1420.                             HideDialogItem(dlg, kPasteAsKindLabel);
  1421.                             HideDialogItem(dlg, kPasteAsKindText);
  1422.                             ShowDialogItem(dlg, kPasteAsKindPopup);
  1423.                         }
  1424.                         else
  1425.                         {
  1426.                             EnablePasteAsOkButton(dlg, kindMenu);
  1427.                         }
  1428.                         
  1429.                         HideDialogItem(dlg, kPasteAsEditorPopup);
  1430.                         HideDialogItem(dlg, kPasteAsEmbedEditorText);
  1431.                         ShowDialogItem(dlg, kPasteAsEditorLabel);
  1432.                         ShowDialogItem(dlg, kPasteAsEditorText);
  1433.                     }
  1434.                     break;
  1435.     
  1436.             case kPasteAsEmbedPict:
  1437.             case kPasteAsEmbedRadioBtn:
  1438.                     if ( result->mergeSetting )
  1439.                     {
  1440.                         result->mergeSetting = kODFalse;
  1441.                         SetMergeEmbedControls(dlg, result->mergeSetting);
  1442.     
  1443.                         // If the user has not changed the kind setting, switch to the preferred kind
  1444.                         kindItemSelected = (ODSShort) GetControlValue(kindPopupControlHandle);
  1445.                         if ( !userChangedKind )
  1446.                         {
  1447.                             // Make sure item is enabled before drawing it!
  1448.                             EnableItem(kindMenu, bestKindIndex);
  1449.                             SetPopupControlValue(kindPopupControlHandle, bestKindIndex);
  1450.                             kindItemSelected = bestKindIndex;
  1451.                         }
  1452.  
  1453.                         // When embedding is chosen, determine the preferred editor, then enable the kind menu
  1454.                         ResetEditorPopup(kindList,
  1455.                                         kindItemSelected,
  1456.                                         translateToList,
  1457.                                         translationIndex,
  1458.                                         editorList,
  1459.                                         editorMenu, 
  1460.                                         editorPopupControlHandle, 
  1461.                                         session);
  1462.  
  1463.                         // Select the preferred editor if specified
  1464.                         ODSShort preferredEditorItem = IndexOfEditorInList(editorList, preferredEditorID);
  1465.                         if ( preferredEditorItem != 0 )
  1466.                             SetPopupControlValue(editorPopupControlHandle, preferredEditorItem);
  1467.  
  1468.                         if ( isMove && contentIsPart )
  1469.                         {
  1470.                             HideDialogItem(dlg, kPasteAsEditorText);
  1471.                             ShowDialogItem(dlg, kPasteAsEmbedEditorText);
  1472.                         }
  1473.                         else
  1474.                         {
  1475.                             HideDialogItem(dlg, kPasteAsEditorLabel);
  1476.                             HideDialogItem(dlg, kPasteAsEditorText);
  1477.                             ShowDialogItem(dlg, kPasteAsEditorPopup);
  1478.                         }
  1479.  
  1480.                         // Now enable the kind items
  1481.                         if ( isMove && contentIsPart )
  1482.                         {
  1483.                             HideDialogItem(dlg, kPasteAsKindPopup);
  1484.                             ShowDialogItem(dlg, kPasteAsKindLabel);
  1485.                             ShowDialogItem(dlg, kPasteAsKindText);
  1486.                         }
  1487.                         else
  1488.                         {
  1489.                             ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
  1490.                             ODEditor selectedEditor = GetSelectedEditor(editorList, editorItem);
  1491.                             EnableKindPopupItems(result->mergeSetting, kindList, translateToList, translationIndex, kindMenu, selectedEditor, nsm);
  1492.                             ODDisposePtr((ODPtr) selectedEditor);
  1493.                             EnablePasteAsOkButton(dlg, kindMenu);
  1494.                         }
  1495.                     }
  1496.                     break;
  1497.     
  1498.             case kPasteAsKindPopup:
  1499.                     kindItemSelected = (ODSShort) GetControlValue(kindPopupControlHandle);
  1500.                     if ( kindItemSelected == kindItemOthers )
  1501.                     {
  1502.                         ODUShort selectedIndex;
  1503.                         ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
  1504.                         ODEditor initialEditorID;
  1505.                         if ( result->mergeSetting )
  1506.                             initialEditorID = ODISOStrFromCStr((char *) mergeEditorID);
  1507.                         else
  1508.                             initialEditorID = GetSelectedEditor(editorList, editorItem);
  1509.                         ODEditor newEditorID = kODNULL;
  1510.  
  1511.                         // Return the kind popup to its current value 
  1512.                         SetPopupControlValue(kindPopupControlHandle, kindItemCurrent);
  1513.                         DeactivateModalDialog(modalFilter);
  1514.                         
  1515.                         if ( session->GetTranslation(ev)->ShowTranslateDialog(
  1516.                                                                 ev,
  1517.                                                                 translateToList,
  1518.                                                                 translationIndex,
  1519.                                                                 &selectedIndex,
  1520.                                                                 initialEditorID,
  1521.                                                                 !result->mergeSetting,
  1522.                                                                 &newEditorID) )
  1523.                         {
  1524.                             // Add translationKind to the list just above "Translate to…", 
  1525.                             //  and make it the current selection.
  1526.                             translationIndex = selectedIndex;
  1527.  
  1528.                             { TempODType translationKind = GetSelectedType(translateToList, translationIndex);
  1529.                               AddTranslationKindToMenu(translationKind, kindMenu, kindItemOthers-1, 
  1530.                                                         kindPopupHasNoTranslationKind, session);
  1531.                             }
  1532.  
  1533.                             if ( kindPopupHasNoTranslationKind )
  1534.                             {
  1535.                                 kindPopupHasNoTranslationKind = kODFalse;
  1536.                                 kindItemOthers += 1;
  1537.                             }
  1538.  
  1539.                             SetPort(dlg);
  1540.                             SetControlValue(kindPopupControlHandle, kindItemOthers-1);
  1541.                             InvalRect(&kindPopupRect);    // Redraw the popup
  1542.  
  1543.                             if ( !result->mergeSetting )
  1544.                             {
  1545.                                 ResetEditorPopup(kindList,
  1546.                                                 kindItemSelected,
  1547.                                                 translateToList,
  1548.                                                 translationIndex,
  1549.                                                 editorList,
  1550.                                                 editorMenu, 
  1551.                                                 editorPopupControlHandle, 
  1552.                                                 session);
  1553.                                 // Select editorID in the list
  1554.                                 ODSShort editorItem = IndexOfEditorInList(editorList, newEditorID);
  1555.                                 if ( editorItem != 0 )
  1556.                                     SetControlValue(editorPopupControlHandle, editorItem);
  1557.                                 InvalRect(&editorPopupRect);    // Redraw the popup
  1558.                             }
  1559.                             ODDisposePtr((ODPtr) initialEditorID);
  1560.                             ODDisposePtr((ODPtr) newEditorID);
  1561.  
  1562.                             userChangedKind = kODTrue;
  1563.                         }
  1564.                     }
  1565.                     else if ( kindItemSelected != kindItemCurrent )
  1566.                     {
  1567.                         userChangedKind = kODTrue;
  1568.                         if ( !result->mergeSetting )
  1569.                         {
  1570.                             ResetEditorPopup(kindList,
  1571.                                             kindItemSelected,
  1572.                                             translateToList,
  1573.                                             translationIndex,
  1574.                                             editorList,
  1575.                                             editorMenu, 
  1576.                                             editorPopupControlHandle, 
  1577.                                             session);
  1578.                             SetPort(dlg);
  1579.                             InvalRect(&editorPopupRect);    // Redraw the popup
  1580.                         }
  1581.                     }
  1582.                     EnablePasteAsOkButton(dlg, kindMenu);
  1583.                     break;
  1584.             default:
  1585.                     break;
  1586.             }
  1587.         } while ((itemHit != kPasteAsOKBtn) && (itemHit != kPasteAsCancelBtn));
  1588.         
  1589.         if ( itemHit == kPasteAsOKBtn )
  1590.         {
  1591.             // update from "View" popup
  1592.             if ( !result->mergeSetting )
  1593.                 result->selectedView = GetViewSelected(dlg, session);
  1594.     
  1595.             // update from "Kind" popup
  1596.             if ( (!result->mergeSetting) && isMove && contentIsPart )
  1597.             {
  1598.                 // Selected kind is the best kind
  1599.                 result->selectedKind = GetSelectedType(kindList, bestKindIndex);
  1600.             }
  1601.             else
  1602.             {
  1603.                 ODSShort kindItem = (ODSShort) GetControlValue(kindPopupControlHandle);
  1604.                 ODSShort kindCount = (ODSShort) kindList->Count(ev);
  1605.                 if (kindItem <= kindCount)
  1606.                 {
  1607.                     result->selectedKind = GetSelectedType(kindList, kindItem);
  1608.                 }
  1609.                 else
  1610.                 {
  1611.                     result->selectedKind = GetSelectedType(translateToList, translationIndex);
  1612.                     result->translateKind = GetSelectedType(kindList, GetIndexedElement(translateFromList, translationIndex));
  1613.                 }
  1614.             }
  1615.  
  1616.             // update from "Editor" popup
  1617.             if ( (!result->mergeSetting) && (!isMove || !contentIsPart) )
  1618.             {
  1619.                 ODSShort editorItem = (ODSShort) GetControlValue(editorPopupControlHandle);
  1620.                 result->editor = GetSelectedEditor(editorList, editorItem);
  1621.             }
  1622.         }
  1623.     
  1624.     CATCH_ALL
  1625.         ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  1626.         ODDisposeRoutineDescriptor(DrawDeactiveItemUPP);
  1627.         ODDisposeRoutineDescriptor(DrawKindNameUPP);
  1628.         ODDisposeRoutineDescriptor(DrawEditorNameUPP);
  1629.         ODDisposeRoutineDescriptor(DrawEmbeddedEditorNameUPP);
  1630.         ODDisposeRoutineDescriptor(modalFilter);
  1631.  
  1632.         refSaved = BeginUsingLibraryResources();
  1633.         if ( kindMenu )
  1634.         {
  1635.             DeleteMenu(kPasteAsKindPopupMenu);
  1636.             ReleaseResource((Handle) kindMenu);
  1637.         }
  1638.         if ( editorMenu )
  1639.         {
  1640.             DeleteMenu(kPasteAsEditorPopupMenu);
  1641.             ReleaseResource((Handle) editorMenu);
  1642.         }
  1643.         ODDisposeDialog(dlg);
  1644.         EndUsingLibraryResources(refSaved);
  1645.  
  1646.         ODDisposePtr((ODPtr) mergeEditorID);
  1647.         ODDisposePtr((ODPtr) embedEditorID);
  1648.         ODDisposePtr((ODPtr) preferredEditorID);
  1649.         ODDisposePtr((ODPtr) bestKind);
  1650.  
  1651.         ODDeleteObject(kindList);
  1652.         ODDeleteObject(translateToList);
  1653.         ODDeleteObject(translateFromList);
  1654.         delete editorList; editorList = kODNULL;
  1655.  
  1656.         DisposeGlobalODNameAndZeroPtr(&gEditorName);
  1657.         DisposeGlobalODNameAndZeroPtr(&gEmbeddedEditorName);
  1658.  
  1659.         SetPort(savePort);
  1660.         RERAISE;
  1661.     ENDTRY;
  1662.  
  1663.     DisposeRoutineDescriptor(DrawBoxItemUPP);
  1664.     DisposeRoutineDescriptor(DrawDeactiveItemUPP);
  1665.     DisposeRoutineDescriptor(DrawKindNameUPP);
  1666.     DisposeRoutineDescriptor(DrawEditorNameUPP);
  1667.     DisposeRoutineDescriptor(DrawEmbeddedEditorNameUPP);
  1668.     DisposeRoutineDescriptor(modalFilter);
  1669.  
  1670.     refSaved = BeginUsingLibraryResources();
  1671.     if ( kindMenu )
  1672.     {
  1673.         DeleteMenu(kPasteAsKindPopupMenu);
  1674.         ReleaseResource((Handle) kindMenu);
  1675.     }
  1676.     if ( editorMenu )
  1677.     {
  1678.         DeleteMenu(kPasteAsEditorPopupMenu);
  1679.         ReleaseResource((Handle) editorMenu);
  1680.     }
  1681.     DisposeDialog(dlg);
  1682.     EndUsingLibraryResources(refSaved);
  1683.  
  1684.     ODDisposePtr((ODPtr) mergeEditorID);
  1685.     ODDisposePtr((ODPtr) embedEditorID);
  1686.     ODDisposePtr((ODPtr) preferredEditorID);
  1687.     ODDisposePtr((ODPtr) bestKind);
  1688.  
  1689.     ODDeleteObject(kindList);
  1690.     ODDeleteObject(translateToList);
  1691.     ODDeleteObject(translateFromList);
  1692.     delete editorList; editorList = kODNULL;
  1693.  
  1694.     DisposeGlobalODNameAndZeroPtr(&gEditorName);
  1695.     DisposeGlobalODNameAndZeroPtr(&gEmbeddedEditorName);
  1696.  
  1697.     session->GetWindowState(ev)->ActivateFrontWindows(ev);
  1698.  
  1699.     SetPort(savePort);
  1700.  
  1701.     return (itemHit == kPasteAsOKBtn);
  1702. }
  1703.  
  1704. //------------------------------------------------------------------------------
  1705. // ResetEditorPopup
  1706. //------------------------------------------------------------------------------
  1707.  
  1708. ODStatic void ResetEditorPopup(ODTypeList* kindList,
  1709.                                 ODUShort kindIndex,
  1710.                                 ODTypeList* translateToList,
  1711.                                 ODUShort translateToIndex,
  1712.                                 EditorSet* editorList,
  1713.                                 MenuHandle editorMenu, 
  1714.                                 ControlHandle popupCtlHndl, 
  1715.                                 ODSession* session)
  1716. {
  1717.     Environment* ev = somGetGlobalEnvironment();
  1718.     TempODType kind = kODNULL;
  1719.  
  1720.     ODSShort kindCount = (ODSShort) kindList->Count(ev);
  1721.     if (kindIndex <= kindCount)
  1722.         kind = GetSelectedType(kindList, kindIndex);
  1723.     else
  1724.         kind = GetSelectedType(translateToList, translateToIndex);
  1725.  
  1726.     editorList->RemoveAllEditors();
  1727.     SetupEditorMenu(kind,
  1728.                     editorList,
  1729.                     editorMenu,
  1730.                     popupCtlHndl,
  1731.                     session);
  1732. }
  1733.  
  1734. //------------------------------------------------------------------------------
  1735. // PrepareToDrawGray
  1736. //------------------------------------------------------------------------------
  1737. //
  1738. // Sets the foreground color to the best color midway between the forground and
  1739. // background colors; usually gray.  If no intermediate gray is available (4 or
  1740. // fewer colors available), the pen pattern is set to draw gray.
  1741.  
  1742. ODStatic Boolean PrepareToDrawGray(DialogPtr theDialog, short theItem, RGBColor* fgSaveColor)
  1743. {
  1744.     Boolean result = false;
  1745.     const short kColorPort = 0xC000;
  1746.     
  1747.     Boolean isColorPort = ((((CGrafPtr)theDialog)->portVersion & kColorPort) == kColorPort);
  1748.     
  1749.     if ( isColorPort )
  1750.     {
  1751.         RGBColor    fgNewColor;
  1752.         RGBColor    bgColor;
  1753.  
  1754.         Rect         itemRect;
  1755.         Handle        itemHandle;
  1756.         short        itemKind;
  1757.  
  1758.         GetBackColor(&bgColor);
  1759.         GetForeColor(fgSaveColor);
  1760.         fgNewColor = *fgSaveColor;
  1761.         
  1762.         GetDialogItem(theDialog, kPasteAsOKBtn, &itemKind, &itemHandle, &itemRect);
  1763.  
  1764.         Rect globalRect = itemRect;
  1765.         LocalToGlobal((Point *)&(globalRect.top));
  1766.         LocalToGlobal((Point *)&(globalRect.bottom));
  1767.         GDHandle targetDevice = GetMaxDevice(&globalRect);
  1768.         
  1769.         result = GetGray(targetDevice, &bgColor, &fgNewColor);
  1770.  
  1771.         if ( result )
  1772.             RGBForeColor(&fgNewColor);
  1773.     }
  1774.     
  1775.     if ( !result )
  1776.     {
  1777. #ifdef THINK_CPLUS
  1778.         PenPat(ODQDGlobals.gray);
  1779. #else
  1780.         PenPat(&ODQDGlobals.gray);
  1781. #endif
  1782.     }
  1783.  
  1784.     return result;
  1785. }
  1786.  
  1787. //------------------------------------------------------------------------------
  1788. // DrawDeactivePICTItem
  1789. //------------------------------------------------------------------------------
  1790. //
  1791. // Draws a dimmed image of the preceeding dialog item, which should be
  1792. // beyond the visible area of the dialog, in this item's rectangle.
  1793.  
  1794. ODStatic pascal void DrawDeactivePICTItem(DialogPtr theDialog, short theItem)
  1795. {
  1796.     Rect         itemRect, otherRect;
  1797.     Handle        itemHandle, otherHandle;
  1798.     short        itemKind, otherKind;
  1799.  
  1800.     WindowPtr    savePort;
  1801.     PenState    savePen;
  1802.     
  1803.     RGBColor    fgSaveColor;
  1804.     Boolean        isColor;
  1805.  
  1806.     GetPort(&savePort);
  1807.     SetPort(theDialog);
  1808.     GetPenState(&savePen);
  1809.     PenNormal();
  1810.  
  1811.     // Get this dialog item
  1812.     GetDialogItem(theDialog, theItem, &itemKind, &itemHandle, &itemRect);
  1813.  
  1814.     // Get the dialog item to be drawn disabled
  1815.     GetDialogItem(theDialog, theItem-1, &otherKind, &otherHandle, &otherRect);
  1816.     if ( (otherKind & ~itemDisable) == picItem )
  1817.     {
  1818.         DrawPicture((PicHandle) otherHandle, &itemRect);
  1819.         isColor = PrepareToDrawGray(theDialog, theItem, &fgSaveColor);
  1820.         if ( isColor )
  1821.             PenMode(addMax);
  1822.         else
  1823.             PenMode(patBic);
  1824.         PaintRect(&itemRect);
  1825.         if ( isColor )
  1826.             RGBForeColor(&fgSaveColor);
  1827.     }
  1828.  
  1829.     SetPenState(&savePen);
  1830.     SetPort(savePort);
  1831. }
  1832.  
  1833. //------------------------------------------------------------------------------
  1834. // InitItemActive
  1835. //------------------------------------------------------------------------------
  1836.  
  1837. ODStatic void InitItemActive(
  1838.                     DialogPtr    dlg,
  1839.                     short        itemNumber,
  1840.                     UserItemUPP    itemUPP,
  1841.                     ODBoolean    itemActive)
  1842. {
  1843.     Rect         itemRect, otherRect;
  1844.     Handle        itemHandle, otherHandle;
  1845.     short        itemKind, otherKind;
  1846.  
  1847.     // Get the rectangle from the actual item
  1848.     GetDialogItem(dlg, itemNumber, &otherKind, &otherHandle, &otherRect);
  1849.  
  1850.     // Establish the draw routine and rectangle for the user item
  1851.     GetDialogItem(dlg, itemNumber+1, &itemKind, &itemHandle, &itemRect);
  1852.     SetDialogItem(dlg, itemNumber+1, itemKind, (Handle)itemUPP, &otherRect);
  1853.  
  1854.     if ( itemActive )
  1855.         HideDialogItem(dlg, itemNumber+1);
  1856.     else
  1857.         HideDialogItem(dlg, itemNumber);
  1858. }
  1859.  
  1860. //------------------------------------------------------------------------------
  1861. // SetControlActive
  1862. //------------------------------------------------------------------------------
  1863. ODStatic void SetControlActive(
  1864.                     DialogPtr    dlg,
  1865.                     short        itemNumber,
  1866.                     ODBoolean    itemActive)
  1867. {
  1868.     short        itemType;
  1869.     Handle        itemHandle;
  1870.     Rect        itemRect;
  1871.  
  1872.     GetDialogItem(dlg, itemNumber, &itemType, &itemHandle, &itemRect);
  1873.     ASSERT_CONTROL_ITEM(itemType);
  1874.     HiliteControl((ControlHandle)itemHandle, itemActive ? kControlActive : kControlInactive);
  1875. }
  1876.  
  1877. //------------------------------------------------------------------------------
  1878. // BestContentKind
  1879. //------------------------------------------------------------------------------
  1880. ODStatic ODType BestContentKind(ODStorageUnit* contentSU)
  1881. {
  1882.     Environment* ev = somGetGlobalEnvironment();
  1883.  
  1884.     ODType bestKind = ODGetISOStrProp(ev, contentSU, kODPropPreferredKind, kODISOStr, kODNULL, kODNULL);
  1885.  
  1886.     if ( bestKind == kODNULL )
  1887.     {
  1888.         if (contentSU->Exists(ev, kODPropContents, (ODValueType)kODNULL, 1))
  1889.         {
  1890.             contentSU->Focus(ev, kODPropContents, kODPosUndefined, (ODValueType)kODNULL, 1, kODPosUndefined);
  1891.             bestKind = contentSU->GetType(ev);
  1892.         }
  1893.     }
  1894.     
  1895.     return bestKind;
  1896. }
  1897.  
  1898. //------------------------------------------------------------------------------
  1899. // SetLinkUpdateUpdateControls
  1900. //------------------------------------------------------------------------------
  1901. ODStatic void SetLinkUpdateUpdateControls(DialogPtr dlg, ODBoolean autoUpdateSetting)
  1902. {
  1903.     short    itemType;
  1904.     Handle    itemHandle;
  1905.     Rect    itemRect;
  1906.  
  1907.     GetDialogItem(dlg, kLinkInfoOnSaveRadioBtn, &itemType, &itemHandle, &itemRect);
  1908.     ASSERT_CONTROL_ITEM(itemType);
  1909.     SetControlValue((ControlHandle)itemHandle, autoUpdateSetting);
  1910.     GetDialogItem(dlg, kLinkInfoManualRadioBtn, &itemType, &itemHandle, &itemRect);
  1911.     ASSERT_CONTROL_ITEM(itemType);
  1912.     SetControlValue((ControlHandle)itemHandle, !autoUpdateSetting);
  1913. }
  1914.  
  1915. //------------------------------------------------------------------------------
  1916. // LinkInfoFilterProc
  1917. //------------------------------------------------------------------------------
  1918.  
  1919. static pascal Boolean
  1920. LinkInfoFilterProc(DialogPtr dialog, EventRecord *event, short *itemHit)
  1921. {    
  1922.     // If the event is a deactivate event, the ok button must be deactivated
  1923.     // before the surrounding outline is drawn so it is drawn dim.
  1924.     ODBoolean rslt = ODButtonKeyFilterProc(dialog,event,itemHit);
  1925.  
  1926.     if ( event->what == activateEvt )
  1927.     {
  1928.         ODOutlineDefaultButtonDrawProc(dialog, kLinkInfoDefaultButtonItem);
  1929.     }
  1930.  
  1931.     return rslt;
  1932. }
  1933.  
  1934. //------------------------------------------------------------------------------
  1935. // ShowLinkInfo
  1936. //------------------------------------------------------------------------------
  1937.  
  1938. ODStatic ODBoolean ShowLinkInfo(
  1939.                         DialogPtr              dlg,
  1940.                         ConstStr255Param    creationDate,
  1941.                         ConstStr255Param    creationTime,
  1942.                         ConstStr255Param    modificationDate,
  1943.                         ConstStr255Param    modificationTime,
  1944.                         ODBoolean            needsUpdate,
  1945.                         ODLinkInfoResult*    infoResult
  1946.                         )
  1947. {
  1948.     short    itemHit;
  1949.  
  1950.     ParamText(creationDate, creationTime, modificationDate, modificationTime);
  1951.  
  1952.     ShowWindow(dlg);
  1953.     
  1954.     ModalFilterUPP modalFilter = NewModalFilterProc(LinkInfoFilterProc);
  1955.  
  1956.     do {
  1957.         ODSLong refSaved = BeginUsingLibraryResources();
  1958.         ModalDialog(modalFilter, &itemHit);
  1959.         EndUsingLibraryResources(refSaved);
  1960.  
  1961.         switch (itemHit)
  1962.         {
  1963.         case kLinkInfoManualRadioBtn :
  1964.             if ( infoResult->autoUpdate )
  1965.             {
  1966.                 infoResult->autoUpdate = kODFalse;
  1967.                 SetLinkUpdateUpdateControls(dlg, infoResult->autoUpdate);
  1968.                 SetControlActive(dlg, kLinkInfoUpdateBtn, needsUpdate);
  1969.             }
  1970.             break;
  1971.             
  1972.         case kLinkInfoOnSaveRadioBtn :
  1973.             if ( !infoResult->autoUpdate )
  1974.             {
  1975.                 infoResult->autoUpdate = kODTrue;
  1976.                 SetLinkUpdateUpdateControls(dlg, infoResult->autoUpdate);
  1977.                 SetControlActive(dlg, kLinkInfoUpdateBtn, kODFalse);
  1978.             }
  1979.             break;
  1980.         }
  1981.     } while ((itemHit != kLinkInfoOKBtn) && (itemHit != kLinkInfoCancelBtn) &&
  1982.              (itemHit != kLinkInfoUpdateBtn) && (itemHit != kLinkInfoBreakLinkBtn) &&
  1983.              (itemHit != kLinkInfoFindSrcBtn));
  1984.  
  1985.     switch (itemHit) {
  1986.     case kLinkInfoOKBtn:
  1987.             infoResult->action = kODLinkInfoOk;
  1988.             break;
  1989.     case kLinkInfoUpdateBtn:
  1990.             infoResult->action = kODLinkInfoUpdateNow;
  1991.             break;
  1992.     case kLinkInfoBreakLinkBtn:
  1993.             infoResult->action = kODLinkInfoBreakLink;
  1994.             break;
  1995.     case kLinkInfoFindSrcBtn:
  1996.             infoResult->action = kODLinkInfoFindSource;
  1997.             break;
  1998.     default:
  1999.             infoResult->action = kODLinkInfoCancel;
  2000.             break;
  2001.     }
  2002.  
  2003.     ODDisposeRoutineDescriptor(modalFilter);
  2004.  
  2005.     return (itemHit != kLinkInfoCancelBtn);
  2006. }
  2007.  
  2008. //------------------------------------------------------------------------------
  2009. // DrawKindName
  2010. //------------------------------------------------------------------------------
  2011.  
  2012. pascal void DrawKindName(DialogPtr dialog, SInt16 item)
  2013. {
  2014.     short    itemType;
  2015.     Handle    itemHandle;
  2016.     Rect    itemRect;
  2017.  
  2018.     GetDialogItem(dialog, item, &itemType, &itemHandle, &itemRect);
  2019.  
  2020.     DrawITextInDlogBox(gKindName, &itemRect, dialog, kODTrue);
  2021. }
  2022.  
  2023. //------------------------------------------------------------------------------
  2024. // ShowLinkSourceInfo
  2025. //------------------------------------------------------------------------------
  2026.  
  2027. ODBoolean ShowLinkSourceInfo(
  2028.                 ODBaseLinkSource*    linkSource,
  2029.                 ODUpdateID            change,
  2030.                 ODBoolean            changesAllowed,
  2031.                 ODLinkInfoResult*    infoResult)
  2032. {
  2033.     Environment* ev = somGetGlobalEnvironment();
  2034.  
  2035.     WindowPtr    savePort;                        ODVolatile(savePort);
  2036.     GetPort(&savePort);
  2037.     ODSLong        refSaved;
  2038.  
  2039.     DialogPtr      dlg = kODNULL;                    ODVolatile(dlg);
  2040.     UserItemUPP DrawBoxItemUPP = kODNULL;        ODVolatile(DrawBoxItemUPP);
  2041.     UserItemUPP DrawKindNameUPP = kODNULL;        ODVolatile(DrawKindNameUPP);
  2042.     short        itemType;
  2043.     Handle        itemHandle;
  2044.     Rect        itemRect;
  2045.     Str255        creationDate, modificationDate;
  2046.     Str255        creationTime, modificationTime;
  2047.     ODType        kind;
  2048.     ODBoolean    needsUpdate;
  2049.     ODBoolean    result;
  2050.  
  2051.     TRY
  2052.         ODSession* session = linkSource->GetStorageUnit(ev)->GetSession(ev);
  2053.         ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
  2054.         
  2055.         {
  2056.             CUsingLibraryResources r;
  2057.             dlg = ODGetNewDialog(ev, kLinkSrcInfoDlgID, session, kNoDefaultButton);
  2058.             THROW_IF_NULL(dlg);
  2059.         }
  2060.  
  2061.         SetPort(dlg);
  2062.         
  2063.         {    CUsingLibraryResources r;
  2064.             SetDialogTextStyle(dlg, kLinkSrcInfoDlgID, smCurrentScript);
  2065.         }
  2066.     
  2067.         // Set the draw routine for the default button outline item
  2068.         GetDialogItem(dlg, kLinkInfoDefaultButtonItem, &itemType, &itemHandle, &itemRect);
  2069.         SetDialogItem(dlg, kLinkInfoDefaultButtonItem, itemType, (Handle)GetODOutlineDefaultButtonDrawProc(), &itemRect);
  2070.         
  2071.         // Vertical and horizontal lines need to be drawn
  2072.         GetDialogItem(dlg, kLinkInfoSeparator, &itemType, &itemHandle, &itemRect);
  2073.         DrawBoxItemUPP = NewUserItemProc(DrawGrayBoxItem);
  2074.         SetDialogItem(dlg, kLinkInfoSeparator, itemType, (Handle)DrawBoxItemUPP, &itemRect);
  2075.         
  2076.         ODLinkKey key;
  2077.         if (linkSource->Lock(ev, 0, &key))
  2078.         {
  2079.             TRY
  2080.                 ODStorageUnit*    contentSU = linkSource->GetContentStorageUnit(ev, key);
  2081.         
  2082.                 // Set up kind
  2083.                 kind = BestContentKind(contentSU);
  2084.                 DisposeGlobalODNameAndZeroPtr(&gKindName);
  2085.                 if ( kind && GetUserKindFromKind(nsm, kind, &gKindName) )
  2086.                 {
  2087.                     GetDialogItem(dlg, kLinkInfoKind, &itemType, &itemHandle, &itemRect);
  2088.                     DrawKindNameUPP = NewUserItemProc(DrawKindName);
  2089.                     SetDialogItem(dlg, kLinkInfoKind, userItem+itemDisable, (Handle) DrawKindNameUPP, &itemRect);
  2090.                 }
  2091.                 ODDisposePtr((ODPtr) kind);
  2092.     
  2093.                 // Set up creation date
  2094.                 SetDateTimeStrings(ODGetCreationDate(ev, ODGetSUFromPstObj(ev, linkSource)),
  2095.                                     creationDate, creationTime);
  2096.                 
  2097.                 // Set up modified date
  2098.                 SetDateTimeStrings(linkSource->GetChangeTime(ev), modificationDate, modificationTime);
  2099.             CATCH_ALL
  2100.                 linkSource->Unlock(ev, key);
  2101.                 RERAISE;
  2102.             ENDTRY
  2103.     
  2104.             linkSource->Unlock(ev, key);
  2105.         }
  2106.         
  2107.         // Set up Send Updates
  2108.         SetLinkUpdateUpdateControls(dlg, infoResult->autoUpdate);
  2109.         
  2110.         needsUpdate = (change == kODUnknownUpdate) || (change != linkSource->GetUpdateID(ev));
  2111.         
  2112.         // Disable Update Now button if updates are automatic or link is up to date.
  2113.         if ( infoResult->autoUpdate || !needsUpdate )
  2114.         {
  2115.             GetDialogItem(dlg, kLinkInfoUpdateBtn, &itemType, &itemHandle, &itemRect);
  2116.             ASSERT_CONTROL_ITEM(itemType);
  2117.             HiliteControl((ControlHandle)itemHandle, kControlInactive);
  2118.         }
  2119.     
  2120.         // Disable some items if changes are not allowed or draft is read only
  2121.         if ( !changesAllowed || DraftIsReadOnly(ev, linkSource->GetStorageUnit(ev)) )
  2122.         {
  2123.             SetControlActive(dlg, kLinkInfoOnSaveRadioBtn, kODFalse);
  2124.             SetControlActive(dlg, kLinkInfoManualRadioBtn, kODFalse);
  2125.             SetControlActive(dlg, kLinkInfoBreakLinkBtn, kODFalse);
  2126.             SetControlActive(dlg, kLinkInfoUpdateBtn, kODFalse);
  2127.         }
  2128.  
  2129.         result = ShowLinkInfo(dlg, creationDate, creationTime, modificationDate, 
  2130.                                 modificationTime, needsUpdate, infoResult);
  2131.     
  2132.     CATCH_ALL
  2133.         ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  2134.         ODDisposeRoutineDescriptor(DrawKindNameUPP);
  2135.  
  2136.         refSaved = BeginUsingLibraryResources();
  2137.         ODDisposeDialog(dlg);
  2138.         EndUsingLibraryResources(refSaved);
  2139.  
  2140.         SetPort(savePort);
  2141.         RERAISE;
  2142.     ENDTRY
  2143.  
  2144.     ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  2145.     ODDisposeRoutineDescriptor(DrawKindNameUPP);
  2146.  
  2147.     refSaved = BeginUsingLibraryResources();
  2148.     ODDisposeDialog(dlg);
  2149.     EndUsingLibraryResources(refSaved);
  2150.  
  2151.     SetPort(savePort);
  2152.  
  2153.     return result;
  2154. }
  2155.                 
  2156. //------------------------------------------------------------------------------
  2157. // SetDateTimeStrings
  2158. //------------------------------------------------------------------------------
  2159.  
  2160. ODStatic void SetDateTimeStrings(
  2161.                     ODULong        dateTime,
  2162.                     Str255        dateString, 
  2163.                     Str255        timeString)
  2164. {
  2165.     if ( dateTime == 0 )
  2166.     {
  2167.         CUsingLibraryResources r;
  2168.  
  2169.         StringHandle str = GetString(kODLinkInfoStrUnknownID);
  2170.         if ( str != kODNULL )
  2171.         {
  2172.             ODLockHandle((ODHandle) str);
  2173.             ODBlockMove((ODPtr) *str, (ODPtr) dateString, (ODULong) (*str[0])+1);
  2174.             ODUnlockHandle((ODHandle) str);
  2175.             ReleaseResource((Handle) str);
  2176.         }
  2177.         else
  2178.         {
  2179.             dateString[0] = (char) 0;
  2180.         }
  2181.         timeString[0] = (char) 0;
  2182.     }
  2183.     else
  2184.     {
  2185.         DateString(dateTime, abbrevDate, dateString, kODNULL);
  2186.         TimeString(dateTime, kODFalse, timeString, kODNULL);
  2187.     }
  2188. }
  2189.  
  2190. //------------------------------------------------------------------------------
  2191. // DraftIsReadOnly
  2192. //------------------------------------------------------------------------------
  2193. ODStatic ODBoolean DraftIsReadOnly(Environment* ev, ODStorageUnit* su)
  2194. {
  2195.     return (!HAS_WRITE_ACCESS(su->GetDraft(ev)->GetPermissions(ev)));
  2196. }
  2197.  
  2198. //------------------------------------------------------------------------------
  2199. // ShowLinkDestinationInfo
  2200. //------------------------------------------------------------------------------
  2201.  
  2202. ODBoolean ShowLinkDestinationInfo(
  2203.                 ODBaseLink*            link,
  2204.                 ODLinkInfo*         info,
  2205.                 ODBoolean            changesAllowed,
  2206.                 ODLinkInfoResult*    infoResult)
  2207. {
  2208.     Environment* ev = somGetGlobalEnvironment();
  2209.  
  2210.     WindowPtr    savePort;                        ODVolatile(savePort);
  2211.     GetPort(&savePort);
  2212.     ODSLong        refSaved;
  2213.  
  2214.     short          itemType;
  2215.     DialogPtr      dlg = kODNULL;                    ODVolatile(dlg);
  2216.     UserItemUPP DrawBoxItemUPP = kODNULL;        ODVolatile(DrawBoxItemUPP);
  2217.     UserItemUPP DrawKindNameUPP = kODNULL;        ODVolatile(DrawKindNameUPP);
  2218.     Handle        itemHandle;
  2219.     Rect        itemRect;
  2220.     Str255        creationDate, modificationDate;
  2221.     Str255        creationTime, modificationTime;
  2222.     ODBoolean    needsUpdate;
  2223.     ODBoolean    result;
  2224.  
  2225.     TRY
  2226.         ODSession* session = link->GetStorageUnit(ev)->GetSession(ev);
  2227.         ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
  2228.  
  2229.         {
  2230.             CUsingLibraryResources r;
  2231.             dlg = ODGetNewDialog(ev, kLinkDstInfoDlgID, session, kNoDefaultButton);
  2232.             THROW_IF_NULL(dlg);
  2233.         }
  2234.  
  2235.         SetPort(dlg);    
  2236.  
  2237.         {    CUsingLibraryResources r;
  2238.             SetDialogTextStyle(dlg, kLinkDstInfoDlgID, smCurrentScript);
  2239.         }
  2240.     
  2241.         // Set the draw routine for the default button outline item
  2242.         GetDialogItem(dlg, kLinkInfoDefaultButtonItem, &itemType, &itemHandle, &itemRect);
  2243.         SetDialogItem(dlg, kLinkInfoDefaultButtonItem, itemType, (Handle)GetODOutlineDefaultButtonDrawProc(), &itemRect);
  2244.         
  2245.         // Vertical and horizontal lines need to be drawn
  2246.         GetDialogItem(dlg, kLinkInfoSeparator, &itemType, &itemHandle, &itemRect);
  2247.         DrawBoxItemUPP = NewUserItemProc(DrawGrayBoxItem);
  2248.         SetDialogItem(dlg, kLinkInfoSeparator, itemType, (Handle) DrawBoxItemUPP, &itemRect);
  2249.         
  2250.         // Set up kind
  2251.         DisposeGlobalODNameAndZeroPtr(&gKindName);
  2252.         if ( info->kind && GetUserKindFromKind(nsm, info->kind, &gKindName) )
  2253.         {
  2254.             GetDialogItem(dlg, kLinkInfoKind, &itemType, &itemHandle, &itemRect);
  2255.             DrawKindNameUPP = NewUserItemProc(DrawKindName);
  2256.             SetDialogItem(dlg, kLinkInfoKind, userItem+itemDisable, (Handle) DrawKindNameUPP, &itemRect);
  2257.         }
  2258.  
  2259.         // Set up creation date
  2260.         SetDateTimeStrings(info->creationTime, creationDate, creationTime);
  2261.         
  2262.         // Set up modified date
  2263.         SetDateTimeStrings(info->changeTime, modificationDate, modificationTime);
  2264.  
  2265.         // Set up Send Updates
  2266.         SetLinkUpdateUpdateControls(dlg, info->autoUpdate);
  2267.         
  2268.         needsUpdate = (info->change == kODUnknownUpdate) || (info->change != link->GetUpdateID(ev));
  2269.         
  2270.         // Disable Update Now button if updates are automatic or destination is up to date.
  2271.         if ( info->autoUpdate || !needsUpdate )
  2272.         {
  2273.             SetControlActive(dlg, kLinkInfoUpdateBtn, kODFalse);
  2274.         }
  2275.  
  2276.         // Disable some items if changes are not allowed or draft is read only
  2277.         if ( !changesAllowed || DraftIsReadOnly(ev, link->GetStorageUnit(ev)) )
  2278.         {
  2279.             SetControlActive(dlg, kLinkInfoOnSaveRadioBtn, kODFalse);
  2280.             SetControlActive(dlg, kLinkInfoManualRadioBtn, kODFalse);
  2281.             SetControlActive(dlg, kLinkInfoBreakLinkBtn, kODFalse);
  2282.             SetControlActive(dlg, kLinkInfoUpdateBtn, kODFalse);
  2283.         }
  2284.  
  2285.         result = ShowLinkInfo(dlg, creationDate, creationTime, modificationDate, 
  2286.                                 modificationTime, needsUpdate, infoResult);
  2287.  
  2288.     CATCH_ALL
  2289.         ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  2290.         ODDisposeRoutineDescriptor(DrawKindNameUPP);
  2291.  
  2292.         refSaved = BeginUsingLibraryResources();
  2293.         ODDisposeDialog(dlg);
  2294.         EndUsingLibraryResources(refSaved);
  2295.  
  2296.         SetPort(savePort);
  2297.         RERAISE;
  2298.     ENDTRY
  2299.  
  2300.     ODDisposeRoutineDescriptor(DrawBoxItemUPP);
  2301.     ODDisposeRoutineDescriptor(DrawKindNameUPP);
  2302.  
  2303.     refSaved = BeginUsingLibraryResources();
  2304.     ODDisposeDialog(dlg);
  2305.     EndUsingLibraryResources(refSaved);
  2306.  
  2307.     SetPort(savePort);
  2308.  
  2309.     return result;
  2310. }
  2311.  
  2312. //------------------------------------------------------------------------------
  2313. // ShowLinkUpdateAlert
  2314. //------------------------------------------------------------------------------
  2315.  
  2316. ODBoolean ShowLinkUpdateAlert( /*ODUShort count*/ )
  2317. {
  2318.     Environment* ev = somGetGlobalEnvironment();
  2319.  
  2320.     // ODUnused(count);
  2321.  
  2322.     gSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  2323.     ODSShort alertResult = ShowAlert(ev, kLinkUpdateAlertID, GetODButtonKeyFilterProc(), gSession);
  2324.     gSession->GetWindowState(ev)->ActivateFrontWindows(ev);
  2325.  
  2326.     ResetAlertStage();
  2327.  
  2328.     return (alertResult == kLinkUpdateContinueBtn);
  2329. }
  2330.  
  2331. //------------------------------------------------------------------------------
  2332. // ShowLinkStatusAlert
  2333. //------------------------------------------------------------------------------
  2334.  
  2335. void ShowLinkStatusAlert(ODError error)
  2336. {
  2337.     Environment* ev = somGetGlobalEnvironment();
  2338.  
  2339.     ODSShort alertID;
  2340.     Str63 numberString;
  2341.  
  2342.     NumToString(error, numberString);
  2343.     ParamText(numberString, 0, 0, 0);
  2344.  
  2345.     if ( error == kODErrCannotFindLinkSourceEdition )
  2346.         alertID = kLinkEditionAlertID;
  2347.     else
  2348.         alertID = kLinkStatusAlertID;
  2349.  
  2350.     gSession->GetWindowState(ev)->DeactivateFrontWindows(ev);
  2351.     ShowAlert(ev, alertID, GetODButtonKeyFilterProc(), gSession);
  2352.     gSession->GetWindowState(ev)->ActivateFrontWindows(ev);
  2353.  
  2354.     ResetAlertStage();
  2355. }
  2356.